[Tutor] input and raw input
Peter Otten
__peter__ at web.de
Sat Sep 25 19:17:19 CEST 2010
Brian Jones wrote:
> No need for the 're' module. Even in the case where both can be used
> together, you can still just use string methods:
>
>>>> s
> '12, 13 14'
>>>> s.replace(',', '').split(' ')
> ['12', '13', '14']
I think to replace "," with " " and then split() without explicit separator
is slightly more robust. Compare:
>>> s = "12,34, 56 789"
>>> s.replace(",", " ").split()
['12', '34', '56', '789']
>>> s.replace(",", "").split(" ")
['1234', '56', '', '789']
Peter
More information about the Tutor
mailing list