python - unpack the first two elements in list/tuple -


is there way in python this:

a, b, = 1, 3, 4, 5 

and then:

>>> 1 >>> b 3 

(the above code doesn't work throw valueerror: many values unpack.)

just add nolen's answer, in python 3, can unpack rest, this:

>>> a, b, *rest = 1, 2, 3, 4, 5, 6, 7 >>> 1 >>> rest [3, 4, 5, 6, 7] 

unfortunately, not work in python 2 though.


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -