Add another tuple to a tuple of tuples

后端 未结 4 712
猫巷女王i
猫巷女王i 2021-02-01 12:34

I have the following tuple of tuples:

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


        
4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-01 12:41

    Don't convert to a list and back, it's needless overhead. + concatenates tuples.

    >>> foo = ((1,),(2,),(3,))
    >>> foo = ((0,),) + foo
    >>> foo
    ((0,), (1,), (2,), (3,))
    

提交回复
热议问题