Arrays/List, filters, Pytho, Ruby
Arnaud Delobelle
arnodel at gmail.com
Sat Feb 12 18:11:08 EST 2011
Arnaud Delobelle <arnodel at gmail.com> writes:
> "LL.Snark" <ll.snark at gmail.com> writes:
>
>> Hi,
>>
>> 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}
>>
>
> In Python3:
>
>>>> t = [6,7,8,6,7,9,8,4,3,6,7]
>>>> next(filter(t[0].__gt__, t))
> 4
Oops! I realised my mistake the moment I sent the reply. You can do this
to get the index:
>>> next(i for i, x in enumerate(t) if x < t[0])
7
--
Arnaud
More information about the Python-list
mailing list