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 🙁

Asked By: SnarkShark

||

Answers:

You can use +

>>> first = [('a', 1), ('b',2)]
>>> second = [('c',3), ('d',4)]
>>> first + second
[('a', 1), ('b', 2), ('c', 3), ('d', 4)]
Answered By: Chaker
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.