Python split
behavior
Python
>>> ',,,1,2,3,,,4,5,,,'.split(',')
['', '', '', '1', '2', '3', '', '', '4', '5', '', '', '']
Is intuitive, but if you use Ruby's split
in the same way, the empty elements that are continuous at the end are removed and you are addicted to it.
Ruby
> ',,,1,2,3,,,4,5,,,'.split(',')
=> ["", "", "", "1", "2", "3", "", "", "4", "5"]
If you want to behave like Python, pass -1.
Ruby
> ',,,1,2,3,,,4,5,,,'.split(',',-1)
=> ["", "", "", "1", "2", "3", "", "", "4", "5", "", "", ""]
reference
Recommended Posts