#!/usr/bin/python
import itertools
list1 = ['XTN','XES','XSD','XRT','XLI','XME','XLE','XLF','XAR','XLB','XHE','XLK','XLY','XHB','XBI','XLP','XLV','XPH','XLU']
perm = list(itertools.permutations(list1))
print(perm)
Hi, the above code gets a "Killed" on a good sized instance or station and it's running time is unacceptable anyway.
My question is, for the given list, I would like to permute the arrangements but to produce all,so for example, "A", "B", "C"
A
B
C
AB
AC
BC
And so on - anyone have code which can do that for an arbitrary list and not squash the machine?
itertools.permutations()
returns a generator, so you could just... not convert it to a list.
list1 = ['XTN','XES','XSD','XRT','XLI',...]
permutations = itertools.permutations(list1)
for permutation in permutations:
print(permutation)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.