There is a list.
spis = ['qwert', '123', '321'] I need to glue each element of the list with each element. Ie in this case it should turn out like this:
qwert;123 qwert;321 123;qwert 123;321 321;qwert 321;123 Use itertools.permutations :
from itertools import permutations result = ' '.join([';'.join(t) for t in permutations(spis, 2)]) print(result) Conclusion:
qwert;123 qwert;321 123;qwert 123;321 321;qwert 321;123 If the result should be a list:
result = [';'.join(t) for t in permutations(spis, 2)] print(result) Conclusion:
['qwert;123', 'qwert;321', '123;qwert', '123;321', '321;qwert', '321;123'] print(*map(';'.join, permutations(spis, 2))) or print(*[x+';'+y for x in spis for y in spis if x is not y])Source: https://ru.stackoverflow.com/questions/636318/
All Articles