Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > assign only first few items of a tuple/list

Reply
Thread Tools

assign only first few items of a tuple/list

 
 
Daniel Fetchinson
Guest
Posts: n/a
 
      12-04-2012
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
unpacking first few items of iterable Daniel Fetchinson Python 0 12-13-2012 07:37 PM
Re: assign only first few items of a tuple/list Dave Angel Python 0 12-04-2012 10:50 PM
Re: assign only first few items of a tuple/list Tim Chase Python 0 12-04-2012 10:48 PM
Re: assign only first few items of a tuple/list Terry Reedy Python 0 12-04-2012 10:18 PM
Re: assign only first few items of a tuple/list Chris Angelico Python 0 12-04-2012 09:36 PM



Advertisments