'Append a tuple to a list of tuples in python [duplicate]
I want to add a tuple in a list of tuples:
list1 = [('a', 'b'), ('c', 'd')]
tuple1 = ('e', 'f') # this is the tuple I want to add to the list above (list1).
list2 = list1.append(tuple1)
print(list2)
The result should be:
[('a', 'b'), ('c', 'd'), ('e', 'f')]
But instead, I'm finding:
None
Solution 1:[1]
You just did! Check out your list1
list1=[('a','b'),('c','d')]
list2 = list1.copy()
list2.append('e','f')
print(list2)
Explanation
- list.append() method just returns None
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Daniel Exxxe |
