text_1 = "Вася,,,,,,,29.7,,,,задание,,,,,,оценка,,,,,,,4"
text_2 = text_1.replace(",,", ",")
text_3 = text_2.replace(",,", ",")
text_4 = text_3.replace(",,", ",")
....
text_1 = "Вася,,,,,,,29.7,,,,задание,,,,,,оценка,,,,,,,4"
text_2 = text_1.replace(",,", ",")
text_3 = text_2.replace(",,", ",")
text_4 = text_3.replace(",,", ",")
....
print ','.join(v for v text_1.split(',') if v)
1 >>> import re, string
2 >>> text_1 = "Вася,,,,,,,29.7,,,,задание,,,,,,оценка,,,,,,,4"
3 >>> print ','.join((v for v text_1.split',' if v))
SyntaxError: invalid syntax
>>>
print ','.join((v for v in text_1.split(',') if v))
while ',,' in text_1:
text_1 = text_1.replace(',,', ',')
bw
BW
text_1 = "Вася,29.7,задание,оценка,4"
text_1 = "Вася,29.7,задание,оценка,4,"
text_1 = "Вася,29.7,задание,оценка,4"
.................
patt = re.compile("\n")
new_text = patt.sub(',\n', text_1)
.................
-doчем плох обычный replace строки? =)
Код:
text_1 = “Вася,29.7,задание,оценка,4”
……………..
patt = re.compile(“\n”)
new_text = patt.sub(',\n', text_1)
……………..
>>> text="Вася,29.7,задание,оценка,4"
>>> text=text+","
>>> print text
Вася,29.7,задание,оценка,4,