I have a list that I create by parsing some text. Let's say the list looks like
charlist = ['a', 'b', 'c']
I would like to take the following list
numlist = [3, 2, 1]
and join it together so that my combined list looks like
[['a', 3], ['b', 2], ['c', 1]]
is there a simple method for this?
If you want a list of lists rather than a list of tuples you could use:
map(list,zip(charlist,numlist))
The zip builtin function should do the trick.
Example from the docs:
>>> x = [1, 2, 3]
>>> y = [4, 5, 6]
>>> zipped = zip(x, y)
>>> zipped
[(1, 4), (2, 5), (3, 6)]
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