简体   繁体   中英

How can I append two list items to one item with two items inside? (Python)

How can I append two list item into one item, with those two items inside?

    tN2 = []

for i in range(13):
    j1 = tN1[0][i]
    j2 = tN1[1][i]
    tN2.append(j1 and j2) #This does not work but illustrates what I want to do.

您还可以使用列表理解。

tN2 = [(tN1[0][i], tN1[1][i]) for i in range(13)]

You could use nested lists :

tN2.append([j1,j2]) 

Or a tuple :

tN2.append((j1,j2)) 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM