Home

On Oct 2, 10:20 pm, Paul Hankin <paul.han...@gmail.com> wrote:
> On Oct 2, 10:06 pm, brad <byte8b...@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

Or the embarrassingly simple:

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

--
Paul Hankin

previous
next

Re: __call__ considered harmful or indispensable?
Re: An Editor that Skips to the End of a Def
Re: Needless copying in iterations?
Re: C++ Primer ex 7.3
static member in base class
Mam Marzenie
Podaruj Zycie
Nasze Dzieci
Niechciane i Zapomniane
Kidprotect