python combining two lists of tuples into one big list of tuples?
Question:
I’ve searched around and it seems like nobody has asked this question (or at least I can’t find it).
I have two lists of tuples and I want to join them to one list of tuples.
first = [('a', 1), ('b',2)]
second = [('c',3), ('d',4)]
I have tried appending, joining, zipping, but none of those are quite right. I want to get this:
wanted = [('a', 1), ('b',2), ('c',3), ('d',4)]
Is there a simple way to do this?
EDIT: I feel really stupid… of course its the one thing I forgot to try 🙁
Answers:
You can use +
>>> first = [('a', 1), ('b',2)]
>>> second = [('c',3), ('d',4)]
>>> first + second
[('a', 1), ('b', 2), ('c', 3), ('d', 4)]
I’ve searched around and it seems like nobody has asked this question (or at least I can’t find it).
I have two lists of tuples and I want to join them to one list of tuples.
first = [('a', 1), ('b',2)]
second = [('c',3), ('d',4)]
I have tried appending, joining, zipping, but none of those are quite right. I want to get this:
wanted = [('a', 1), ('b',2), ('c',3), ('d',4)]
Is there a simple way to do this?
EDIT: I feel really stupid… of course its the one thing I forgot to try 🙁
You can use +
>>> first = [('a', 1), ('b',2)]
>>> second = [('c',3), ('d',4)]
>>> first + second
[('a', 1), ('b', 2), ('c', 3), ('d', 4)]