List Question

Paul Hankin paul.hankin at gmail.com
Tue Oct 2 23:20:38 CEST 2007


On Oct 2, 10:06 pm, brad <byte8b... at gmail.com> wrote:
> How is this expressed in Python?
>
> If x is in y more than three times:
>      print x
>
> y is a Python list.

Simple and readable:
if len([a for a in y if x == a]) > 3:
    print x

Or the slightly-too-flashy version:
if sum(1 for a in y if x == a) > 3:
    print x

--
Paul Hankin




More information about the Python-list mailing list