why is python string split() not splitting
Solution 1:
split
does not modify the string. It returns a list of the split pieces. If you want to use that list, you need to assign it to something with, e.g., r = r.split(' ')
.
Solution 2:
split
does not split the original string, but returns a list
>>> r = 'court2 13 0 2012 9 2'
>>> r.split(' ')
['court2', '13', '0', '2012', '9', '2']
Solution 3:
Change
r.split(' ')
a.split(' ')
to
r = r.split(' ')
a = a.split(' ')
Explanation: split
doesn't split the string in place, but rather returns a split version.
From documentaion:
split(...)
S.split([sep [,maxsplit]]) -> list of strings
Return a list of the words in the string S, using sep as the
delimiter string. If maxsplit is given, at most maxsplit
splits are done. If sep is not specified or is None, any
whitespace string is a separator and empty strings are removed
from the result.