creating an artificial "last element" in sort list

Ian Kelly ian.g.kelly at gmail.com
Fri Sep 28 23:29:53 EDT 2012


On Fri, Sep 28, 2012 at 6:59 PM, Demian Brecht <demianbrecht at gmail.com> wrote:
>> f = filter(lambda s: s == a[-1], a)
>
> That line's assuming that the last element may also be found in arbitrary locations in the list. If it's guaranteed that they're all contiguous at the upper bounds, I'd just walk the list backwards until I found one that wasn't matching rather than filtering.

The slicing operation in the second line assumes that they're all
collected at the end of the list anyway.



More information about the Python-list mailing list