How to generate and write to text file all possible 4 permutations of the abc without repetition in Python

1 Answer

0 votes
from itertools import permutations

abc = "abcdefghijklmnopqrstuvwxyz"
X = 4

p = list(permutations(abc, X))

f = open("words.txt", "w")

for item in list(p):
    f.write(item[0] + item[1] + item[2] + item[3] + "\n")





'''
run:

abcd
abce
abcf
abcg
abch
abci
abcj
abck
abcl
abcm
abcn
abco
abcp
abcq
abcr
abcs
abct
abcu
abcv
abcw
abcx
abcy
abcz
abdc
abde
abdf
abdg
abdh
abdi
abdj
abdk
abdl
abdm
abdn
abdo
abdp
abdq
abdr
abds
abdt
abdu
abdv
abdw
abdx
abdy
abdz
abec
abed
abef
abeg
abeh
abei
abej
abek
abel
abem
aben
abeo
abep
abeq
aber
abes
abet
abeu
abev
abew
abex
abey
abez
abfc
abfd
abfe
abfg
abfh
abfi
abfj
abfk
abfl
abfm
abfn
abfo
abfp
abfq
abfr
abfs
...

'''

 



answered Oct 3, 2021 by avibootz
...