"/1/2/3/".split("/")
It's too hot & I'm probably being retarded. >>> '/1/2/3/'.split('/') ['', '1', '2', '3',''] Whats with the empty elements at the start and end? Edit: Thanks all, im p
Solution 1:
Compare with:
"1/2/3".split("/")
Empty elements are still elements.
You could use strip('/')
to trim the delimiter from the beginning/end of your string.
Solution 2:
As JLWarlow says, you have an extra '/' in the string. Here's another example:
>>> "//2//3".split('/')
['', '', '2', '', '3']
Solution 3:
Slashes are separators, so there are empty elements before the first and after the last.
Solution 4:
you're splitting on /
. You have 4 /
, so, the list returned will have 5 elements.
Solution 5:
That is exactly what I would expect, but we are all different :)
What would you expect from: : "1,,2,3".split(",") ?
Post a Comment for ""/1/2/3/".split("/")"