Re: Referencing Items in a List of Tuples

2007-02-25 Thread rshepard
On 2007-02-25, Jussi Salmela <[EMAIL PROTECTED]> wrote: > I'm nitpicking, but the OP has a list of tuples: > ec = [ item[2:] for item in mainlist if item[:2] == ('eco','con') ] Jussi, An excellent nit to pick. Thank you, Rich -- http://mail.python.org/mailman/listinfo/python-list

Re: Referencing Items in a List of Tuples

2007-02-25 Thread rshepard
On 2007-02-25, Paddy <[EMAIL PROTECTED]> wrote: > You might also use list comprehensions to accumulate the values you > need: > > ec = [ item[2:] for item in mainlist if item[:2] == ['eco','con'] ] Thank you, Paddy. That's the syntax I couldn't work out myself. Rich -- http://mail.python.or

Re: Referencing Items in a List of Tuples

2007-02-25 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : > While working with lists of tuples is probably very common, none of my > five Python books or a Google search tell me how to refer to specific items > in each tuple. t = "a", "b", "c" assert t[0] == "a" assert t[1] == "b" assert t[2] == "c" > I find references to

Re: Referencing Items in a List of Tuples

2007-02-25 Thread Paddy
On Feb 25, 5:44 pm, Jussi Salmela <[EMAIL PROTECTED]> wrote: > Paddy kirjoitti: > > > > > On Feb 25, 2:01 am, [EMAIL PROTECTED] wrote: > >> While working with lists of tuples is probably very common, none of my > >> five Python books or a Google search tell me how to refer to specific items > >>

Re: Referencing Items in a List of Tuples

2007-02-25 Thread rshepard
On 2007-02-25, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: > Item is ALREADY the "current" tuple... > > for tpl in mainlist: > if tpl[0] == "eco" and tpl[1] == "con": > ec.Append(tpl[2:]) #presuming ec is NOT a list, as Append() >

Re: Referencing Items in a List of Tuples

2007-02-25 Thread Jussi Salmela
Paddy kirjoitti: > On Feb 25, 2:01 am, [EMAIL PROTECTED] wrote: >> While working with lists of tuples is probably very common, none of my >> five Python books or a Google search tell me how to refer to specific items >> in each tuple. I find references to sorting a list of tuples, but not >> extr

Re: Referencing Items in a List of Tuples

2007-02-25 Thread Paddy
On Feb 25, 2:01 am, [EMAIL PROTECTED] wrote: > While working with lists of tuples is probably very common, none of my > five Python books or a Google search tell me how to refer to specific items > in each tuple. I find references to sorting a list of tuples, but not > extracting tuples based on

Re: Referencing Items in a List of Tuples

2007-02-24 Thread Paul Rubin
"Rune Strand" <[EMAIL PROTECTED]> writes: > if you want numeric adressing, try: > for i in range(len(mainlist)): >if mainlist[i][0] == 'eco' etc. Preferable: for i,m in enumerate(mainlist): if m[0] == 'eco' etc. -- http://mail.python.org/mailman/listinfo/python-list

Re: Referencing Items in a List of Tuples

2007-02-24 Thread John Machin
On Feb 25, 1:01 pm, [EMAIL PROTECTED] wrote: > While working with lists of tuples is probably very common, none of my > five Python books or a Google search tell me how to refer to specific items > in each tuple. I find references to sorting a list of tuples, but not > extracting tuples based on

Re: Referencing Items in a List of Tuples

2007-02-24 Thread Rune Strand
On Feb 25, 3:01 am, [EMAIL PROTECTED] wrote: > In my case, I have a list of 9 tuples. Each tuple has 30 items. The first > two items are 3-character strings, the remaining 28 itmes are floats. > > I want to create a new list from each tuple. But, I want the selection of > tuples, and their assi

Referencing Items in a List of Tuples

2007-02-24 Thread rshepard
While working with lists of tuples is probably very common, none of my five Python books or a Google search tell me how to refer to specific items in each tuple. I find references to sorting a list of tuples, but not extracting tuples based on their content. In my case, I have a list of 9 tupl