Ray's playground

 

Recipe 19.4. Unpacking a Few Items in a Multiple Assignment

1 >>> def peel(iterable, arg=1):
2     iterator = iter(iterable)
3     for n in range(arg):
4         yield iterator.__next__()
5     yield iterator
6 

 

1 >>> t5=range(16)
2 >>> a,b,c=peel(t5, 2)
3 >>> a
4 1
5 >>> b
6 2
7 >>> list(c)
8 [345]

 

1>>> t=[1,2,3]
2>>> a, *= t
3>>> a
41
5>>> b
6[23]

 

 

posted on 2009-11-01 17:24  Ray Z  阅读(214)  评论(0编辑  收藏  举报

导航