Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #34258 > unrolled thread

assign only first few items of a tuple/list

Started byDaniel Fetchinson <fetchinson@googlemail.com>
First post2012-12-04 22:25 +0100
Last post2012-12-04 22:25 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

  assign only first few items of a tuple/list Daniel Fetchinson <fetchinson@googlemail.com> - 2012-12-04 22:25 +0100

#34258 — assign only first few items of a tuple/list

FromDaniel Fetchinson <fetchinson@googlemail.com>
Date2012-12-04 22:25 +0100
Subjectassign only first few items of a tuple/list
Message-ID<mailman.478.1354656321.29569.python-list@python.org>
Hi folks, I swear I used to know this but can't find it anywhere.
Say I have a list x = [ 1,2,3,4,5 ] and only care about the first two items.
I'd like to assign the first two items to two variables, something like,

a, b, _ = x

but the above will not work, of course, but what is the common idiom
for this that does?

Cheers,
Daniel


-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web