Concatenating Tuple

前端 未结 7 1266
-上瘾入骨i
-上瘾入骨i 2020-12-29 20:40

Suppose I have a list:

a=[1,2,3,4,5]  

Now I want to convert this list into a tuple. I thought coding something like this would do:

7条回答
  •  灰色年华
    2020-12-29 21:32

    state=()  
    for i in a:  
        state=state+(i,)
    

    The above code will work out to concatenate each time a new tuple (i,) into tuple state.

    I am using python 2.7.9.

提交回复
热议问题