Arrays/List, filters, Pytho, Ruby

Ian ian.g.kelly at gmail.com
Fri Feb 11 23:04:45 CET 2011


On Feb 11, 2:24 pm, "LL.Snark" <ll.sn... at gmail.com> wrote:
> 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}

More Javalicious than Pythonic, but this works:

class ComparisonPredicate:

    def __init__(self, func):
        self.func = func

    def __eq__(self, other):
        return self.func(other)

t = [6, 7, 8, 6, 7, 9, 8, 4, 3, 6, 7]
print(t.index(ComparisonPredicate(lambda x: x < t[0])))



More information about the Python-list mailing list