ребята, я новичок в программировании, пытающийся улучшить процедуру ниже таким образом, чтобы при передаче аргумента: split_string("After the flood ... all the colors came out."," .")
он возвращал:
['After', 'the', 'flood', 'all', 'the', 'colors', 'came', 'out']
, а не это:
['After', 'the', 'flood', '', '', '', '', 'all', 'the', 'colors', 'came', 'out', '']
Есть подсказка, как это сделать?(Я мог бы просто повторить список и удалить элементы '', но я хотел более элегантное решение)
Это процедура:
def split_string(source, separatorList):
splited = [source]
for separator in splitlist:
source = splited
splited = []
print 'separator= ', separator
for sequence in source:
print 'sequence = ', sequence
if sequence not in splitlist and sequence != ' ':
splited = splited + sequence.split(separator)
return splited
print split_string("This is a test-of the,string separation-code!", " ,!-")
print
print split_string("After the flood ... all the colors came out."," .")