Say for example I want to split string "12:30-14:40"
and have the result in a matrix like: [["12","30"],["14","40"]]
.
I can do this in JavaScript with:
"12:30-14:40".split("-").map(function(x) {
return x.split(':');
});
and in Ruby with:
"12:30-14:40".split("-").map{|x| x.split(":")}
What would be the python equivalent for the above?
You can use a list comprehension:
>>> [i.split(':') for i in "12:30-14:40".split('-')]
[['12', '30'], ['14', '40']]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With