On Oct 2, 10:20 pm, Paul Hankin <[EMAIL PROTECTED]> wrote:
> On Oct 2, 10:06 pm, brad <[EMAIL PROTECTED]> 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

Or the embarrassingly simple:

if y.count(x) > 3:
    print x

--
Paul Hankin

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to