Re: [Tutor] single key ordered sequence

2009-01-15 Thread Jervis Whitley
On Fri, Jan 16, 2009 at 10:39 AM, bob gailer wrote: > Jervis Whitley wrote: > >> >> >> On Fri, Jan 16, 2009 at 9:15 AM, Kent Johnson > ken...@tds.net>> wrote: >> >>On Thu, Jan 15, 2009 at 3:44 PM, Jervis Whitley >>mailto:jervi...@gmail.com>> wrote: >>> how about this: >>> items =

Re: [Tutor] single key ordered sequence

2009-01-15 Thread bob gailer
Jervis Whitley wrote: On Fri, Jan 16, 2009 at 9:15 AM, Kent Johnson > wrote: On Thu, Jan 15, 2009 at 3:44 PM, Jervis Whitley mailto:jervi...@gmail.com>> wrote: > how about this: > items = [(1,'a'),(1,'b'),(2,'a'),(3,'a'), > (3,'b'),(4,'a'

Re: [Tutor] single key ordered sequence

2009-01-15 Thread Jervis Whitley
On Fri, Jan 16, 2009 at 9:15 AM, Kent Johnson wrote: > On Thu, Jan 15, 2009 at 3:44 PM, Jervis Whitley > wrote: > > how about this: > > items = [(1,'a'),(1,'b'),(2,'a'),(3,'a'), > > (3,'b'),(4,'a'),(5,'a'),(5,'b'),(5,'c')] > > mydict = dict(items) > > items = [item for item in mydict

Re: [Tutor] single key ordered sequence

2009-01-15 Thread Kent Johnson
On Thu, Jan 15, 2009 at 3:44 PM, Jervis Whitley wrote: > how about this: > items = [(1,'a'),(1,'b'),(2,'a'),(3,'a'), > (3,'b'),(4,'a'),(5,'a'),(5,'b'),(5,'c')] > mydict = dict(items) > items = [item for item in mydict.iteritems()] That only coincidentally preserves order; the order of

Re: [Tutor] single key ordered sequence

2009-01-15 Thread Jervis Whitley
On Fri, Jan 16, 2009 at 4:56 AM, Senthil Kumaran wrote: > > Also, how to practically walk in reverse order in a list without > > copying it (e.g. items[::-1]), > > especially if i need both indexes and items (couldn't find with > > enumerate()). > > > Are you looking for reversed()? > The way you

Re: [Tutor] single key ordered sequence

2009-01-15 Thread Senthil Kumaran
> Also, how to practically walk in reverse order in a list without > copying it (e.g. items[::-1]), > especially if i need both indexes and items (couldn't find with > enumerate()). > Are you looking for reversed()? The way you are doing it is probably OK. But it can be simplified thus: keys = [

Re: [Tutor] single key ordered sequence

2009-01-15 Thread Kent Johnson
On Thu, Jan 15, 2009 at 6:48 AM, spir wrote: > I have a list of tuples element, in which the first item is a kind of key. I > need a target list > with only one tuple per key. But the order must be kept -- so that I cannot > use a temp dictionary. > Additionally, in this case the chosen element

[Tutor] single key ordered sequence

2009-01-15 Thread spir
Hello, a little algorithmic question. I have a list of tuples element, in which the first item is a kind of key. I need a target list with only one tuple per key. But the order must be kept -- so that I cannot use a temp dictionary. Additionally, in this case the chosen element for a repeted ke