I am using split()
and split(\" \")
on the same string. But why is split(\" \")
returning less number of elements than split()>
If you run the help command on the split() function you'll see this:
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.
Therefore the difference between the to is that split()
without specifing the delimiter will delete the empty strings while the one with the delimiter won't.