הכוח באחדות הכוח באחדות - 1 month ago 9
Linux Question

Combination of specific strings

I have file with list of strings :

mystrings.txt:

test
bla
blu
44
ams
p
555
sss
noone
utu
dog
cat


want generate all combination of this world like this :

testbla
blatest
testbla44
test44
testblacat44
44bla
catdogblablu44ams
amsdogblablu

Answer
#!/usr/bin/python
import itertools
import sys

ll = []
for l in sys.stdin.readlines():
  ll.append(l.strip())

for i in range(1, len(ll) - 1):
  l = list(itertools.combinations(ll, i))
  for w in ["".join(x) for x in l]:
    print(w)

One more thing, use it in following way:

cat mystrings.txt | script.py