"LL.Snark" <ll.sn...@gmail.com> writes:

> I'm looking for a pythonic way to translate this short Ruby code :
> t=[6,7,8,6,7,9,8,4,3,6,7]
> i=t.index {|x| x<t.first}

    from itertools import dropwhile

    t=[6,7,8,6,7,9,8,4,3,6,7]
    i = dropwhile(lambda k: t[k]>=t[0], t).next()

Note the above can throw an exception if no suitable element is found.

    t=[6,7,8,6,7,9,8,4,3,6,7]
    i=[j for j in range(len(t)) if t[j]<t[0]][0]

That traverses the whole list even if the desired element is near the
beginning of the list. I don't kow if the Ruby version does the same.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to