A permutation on permutations

Jeff Hinrichs jlh at home.com
Sun Nov 25 22:33:48 EST 2001


Sorry for naiveté but wouldn't this be a candidate for a filter?
I'm just learning python and diveintopython.org has a section on filters
that looks as if this question was made for it.
http://diveintopython.org/regression_filter.html

-Jeff

----- Original Message -----
From: "Kragen Sitaker" <kragen at canonical.org>
Newsgroups: comp.lang.python
To: <python-list at python.org>
Sent: Sunday, November 25, 2001 8:37 PM
Subject: Re: A permutation on permutations


> "Arthur Siegel" <ajs at ix.netcom.com> writes:
> > The following little func does not work as I
> > would expect!!!
> >
> > Something about the iteration of p in t
> > with the list.remove().
> >
> > Is the func as written certifiably bad
> > Python ,  or a bug/trap I fell into?
> >
> > def removedups(t):
> >    for p in t:
> >       if p[-1]>p[0]:
> >          t.remove(p)
> >    print t
>
> It's certifiably bad Python, because modifying a list you're iterating
> over is a bug/trap you fell into.  One general way of solving this is
> to say for p in t[:]: instead of for p in t[:], but I'd probably say
> print [p for p in t if p[-1] > p[0]] instead of the whole function.
>
> --
> http://mail.python.org/mailman/listinfo/python-list





More information about the Python-list mailing list