标签:
#! /usr/bin/python # -*- coding:‘utf-8‘-*- text=‘ab cc sdddd ‘ print ‘ ‘.join(n for n in text.split(‘ ‘) if n) data=[] word=‘‘ for letter in text: if letter!= ‘ ‘: word+=letter else: if word: data.append(word) word=‘‘ if word: data.append(word) print ‘ ‘.join(data)
print ‘ ‘.join(n for n in text.split(‘ ‘) if n)一句就可以搞定,
后面的实现比较麻烦,有点绕
标签:
原文地址:http://www.cnblogs.com/Citizen/p/4857308.html