list permutations and weired list.remove funtion
scarblac at pino.selwerd.nl
Tue May 15 03:47:40 EDT 2001
Tim Gahnström /Bladerman <tim at bladerman.com> wrote in comp.lang.python:
> I am new to python and happende to use the function list.remov(elem) it sure
> is usufull but it rendered me som hours of extra work until I found out that
> it really dont return the list with the elemen removed.
> [1,2,3].remove(2) == null
> instead of
> [1,2,3].remove(2) ==[1,3]
> It seems like it would have been about no cost to let it work that way to?
It changes the list. If it also returned the list, a line like
newlist = l.remove(2)
would suggest that l was unchanged, but it is. So all these functions either
change the list or return the new one, but never both.
> Another question.
> Is there an easy way to get al permutations of a list?
There's no builtin function for this. There was a thread about this a while
ago, search for "list permutations" in this group at
More information about the Python-list