I have a list of tuples with the pattern "id", "text", "language" like this:
a = [('1', 'hello', 'en'), ...]
I would like to increase number of tuple members to "id", "text", "language", "color":
b = [('1', 'hello', 'en', 'red'), ...]
What is the correct way of doing this?
Thank you.
>Solution :
Since a tuple is immutable you have to create new tuples. I assume you want to add this additional value to every tuple in the list.
a = [('1', 'hello', 'en'), ('2', 'hi', 'en')]
color = 'red'
a = [(x + (color,)) for x in a]
print(a)
The result is [('1', 'hello', 'en', 'red'), ('2', 'hi', 'en', 'red')].