I have a file like this:
1 abc
1 def
2 ghi
3 jkl
3 mno
3 pqr
And want to generate a file like this from it:
abc;def
jkl;mno
jkl;pqr
mno;pqr
I have the following code:
with open('input.txt') as f1:
with open("output.csv", "wb") as f2:
cw = csv.writer(f2, delimiter=";")
for l in itertools.groupby((l.split() for l in f1), lambda x: x[0]):
grouped = set(x[1] for x in l[1]) # set avoids duplicate rows
for c in itertools.combinations(grouped, 2):
cw.writerow(c)
But this code does not write anything to the output file. What am I doing wrong?