29 April, 2010

Being Pythonic

I mentioned in my earlier post that we can assign a tuple/list to multiple variables. However both number of elements should match on both sides. One of the options is to assign only fixed number of elements to variables like this
mylist = [1,2,3,4,5]
x,y,z = mylist[:3]
mylist[:3] will return 3 elements from the beginning.

No comments:

Post a Comment