Custom Search

Tuesday, September 21, 2010

python list and tuple unpacking


1) list unpacking:

[item, agent] = [1,2]


2)tuple unpacking:

item, agent = 1,2
(item, agent) = 1,2
item, agent = (1,2)
(item, agent) = (1,2)

I would be willing to bet that the list below is cast into a tuple:
(item, agent) = [1,2]


3) Note it


>>> for i,j in [(1,2), (3,4)]:
.... print i, j
....
1 2
3 4

No comments:

Post a Comment