I have list of strings
a = ['word1, 23, 12','word2, 10, 19','word3, 11, 15']
I would like to create a list
b = [['word1',23,12],['word2', 10, 19],['word3', 11, 15]]
Is this a easy way to do this?
input = ['word1, 23, 12','word2, 10, 19','word3, 11, 15']
output = []
for item in input:
items = item.split(',')
output.append([items[0], int(items[1]), int(items[2])])
Try this:
b = [ entry.split(',') for entry in a ]
b = [ b[i] if i % 3 == 0 else int(b[i]) for i in xrange(0, len(b)) ]
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