user2263800
user2263800

Reputation: 303

python splitting numbers in a list

I am working with a list of lists and I am using coordinates to work my way through the lists. After starting at coordinates 0,0 my list for neighboring nodes looks like this:

[(0, 1), (1, 0), (1, 1)]

Next I choose the first node so it looks like:

(0, 1)

I want to be able to split up the first number from the second and assign them to i and j so I can keep iterating through the loop. Is there any way to accomplish this? I know of for x in list but that loops through each item which is (0,1) and not each individual number.

Upvotes: 1

Views: 210

Answers (1)

Ashwini Chaudhary
Ashwini Chaudhary

Reputation: 251196

Something like this:

In [45]: lis=[(0, 1), (1, 0), (1, 1)]

In [46]: for i,j in lis:
   ....:     print i,j
   ....:     
0 1
1 0
1 1

Upvotes: 3

Related Questions