On 12/27/06, Ian Bicking <[EMAIL PROTECTED]> wrote:

Shannon -jj Behrens wrote:
>
> On 12/27/06, Ian Bicking <[EMAIL PROTECTED]> wrote:
>>
>> Shannon -jj Behrens wrote:
>> >
>> > Agreed!  Merry Christmas to everyone!
>> >
>> > Here is my gift to you all:  write a function that acts like max, but
>> > instead of returning the item in the list, return the index of the
>> > item....
>>
>> Puzzles!
>>
>> def maxindex(seq):
>>      return max(zip(seq, itertools.count()))[1]
>
> maxindex([1, 1, 0]) => 1, but I think it should be 0 ;)

Man, that makes it a lot harder...

def maxindex(seq):
     return -max(zip(seq, (-i for i in itertools.count())))

Seems like count should take a step argument, then I could just use
itertools.count(0, -1), ala:

def count(start=0, step=1):
     while 1:
         yield start
         start += step

def maxindex(seq):
...     return seq.index(max(seq))
...
maxindex([0, 0, 1, 1, -1])
2

I implemented it using a for loop earlier.

Fun,
-jj

--
http://jjinux.blogspot.com/

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to