Instead of nested fors which will grow exponentially in running time, consider
this for removing reversals:
newlist = []
tempdict = {}
for i in oldlist:
try:
tempdict[i]
except:
tempdict[i] = 1
tempdict[i.reverse()] = 1
newlist.append(i)
That's the gneral idea. Pseudocode, so untested. You exploit the O(1) hash
lookup of the dict to avoid the runtime cost of the nested loops, and it is
easier to read as well. Would need to timeit to be sure it helps with your data
sets though. They may be small enough that it doesn't matter.
-----------------------------
Sent from a mobile device with a bad e-mail client.
-----------------------------
On Dec 2, 2010, at 7:54 AM, शंतनू <[email protected]> wrote:
> Following link could be useful:
>
> http://stackoverflow.com/questions/104420/how-to-generate-all-permutations-of-a-list-in-python
>
> On Thu, Dec 2, 2010 at 04:15, Alex Hall <[email protected]> wrote:
> Hi all,
> I am wondering if there is a python package that will find
> permutations? For example, if I have (1, 2, 3), the possibilities I
> want are:
> 12
> 13
> 23
> 123
> 132
> 231
>
> Order does not matter; 21 is the same as 12, but no numbers can
> repeat. If no package exists, does someone have a hint as to how to
> get a function to do this? The one I have right now will not find 132
> or 231, nor will it find 13. TIA.
>
> --
> Have a great day,
> Alex (msg sent from GMail website)
> [email protected]; http://www.facebook.com/mehgcap
> _______________________________________________
> Tutor maillist - [email protected]
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
> _______________________________________________
> Tutor maillist - [email protected]
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor