Add another tuple to a tuple of tuples

Viewed 105978

I have the following tuple of tuples:

my_choices=(
         ('1','first choice'),
         ('2','second choice'),
         ('3','third choice')
)

and I want to add another tuple to the start of it

another_choice = ('0', 'zero choice')

How can I do this?

the result would be:

final_choices=(
             ('0', 'zero choice')
             ('1','first choice'),
             ('2','second choice'),
             ('3','third choice')
    )
5 Answers

You could use the "unpacking operator" (*) to create a new tuple

tpl = ((2, 11), (3, 10),)

tpl = (*tpl, (5, 8))

print(tpl) #prints ((2, 11), (3, 10), (5, 8))

Related