multiib
multiib

Reputation: 23

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.

Upvotes: 1

Views: 55

Answers (2)

Shashwat Swain
Shashwat Swain

Reputation: 69

You can also use list comprehension.

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

Upvotes: 1

Lescurel
Lescurel

Reputation: 11631

You could use nested lists :

tN2.append([j1,j2]) 

Or a tuple :

tN2.append((j1,j2)) 

Upvotes: 0

Related Questions