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


Groups > comp.lang.python > #34258

assign only first few items of a tuple/list

Date 2012-12-04 22:25 +0100
Subject assign only first few items of a tuple/list
From Daniel Fetchinson <fetchinson@googlemail.com>
Newsgroups comp.lang.python
Message-ID <mailman.478.1354656321.29569.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web