Here's an approach(?) using regular expressions. Happy coding :)
#!/usr/bin/env python3.6
import re, io, itertools
if __name__ == '__main__':
groups = [re.subn('(\d*)\s*(.*)', '\g<2>|\g<1>', line, 1)[0].strip().split('|')
for line in io.StringIO(open('f.txt').read())]
enums = sorted([[word, n] for group, n in groups for word in group.split(',')], key=lambda x: x[0])
for a, b in itertools.groupby(enums, lambda x: x[0]):
print(a, ','.join(sorted(map(lambda x: x[1], b), key=int)))
Explanation (of sorts)
#!/usr/bin/env python3.6
import re, io, itertools
if __name__ == '__main__':
# ('\d*') <-- match and capture leading integers
# '\s*' <---- match but don't capture intervening space
# ('.*') <--- match and capture the everything else
# ('\g<2>|\g<1>') <--- swaps the second capture group with the first
# and puts a "|" in between for easy splitting
# io.StringIO is a great wrapper for a string, makes it easy to process text
# re.subn is used to perform the regex swapping
groups = [re.subn('(\d*)\s*(.*)', '\g<2>|\g<1>', line, 1)[0].strip().split('|') for line in io.StringIO(open('f.txt').read())]
# convert [[place1,place2 1], [place3,place4, 2] ...] -> [[place1, 1], place2, 1], [place3, 2], [place4, 2] ...]
enums = sorted([[word, n] for group, n in groups for word in group.split(',')], key=lambda x: x[0])
# group together, extract numbers, ...?, profit!
for a, b in itertools.groupby(enums, lambda x: x[0]):
print(a, ','.join(sorted(map(lambda x: x[1], b), key=int)))
Bonus: one line "piss off your coworkers" edition
#!/usr/bin/env python3.6
import io
import itertools
import re
if __name__ == '__main__':
groups = [[place, lines]
for a, b in itertools.groupby(sorted([[word, n]
for line in io.StringIO(open('f.txt').read())
for group, n in [re.subn('(\d*)\s*(.*)', '\g<2>|\g<1>', line, 1)[0].strip().split('|')]
for word in group.split(',')], key=lambda x: x[0]), key=lambda x: x[0])
for place, lines in [[a, ','.join(sorted(map(lambda x: x[1], b), key=int))]]]
for place, lines in groups:
print(place, lines)
"Bonus" #2: write output directly to file, piss-off-co-worker-no-life edition v1.2
#!/usr/bin/env python3.6
import io
import itertools
import re
if __name__ == '__main__':
with open('output.txt', 'w') as f:
groups = [print(place, lines, file=f)
for a, b in itertools.groupby(sorted([[word, n]
for line in io.StringIO(open('f.txt').read())
for group, n in [re.subn('(\d*)\s*(.*)', '\g<2>|\g<1>', line, 1)[0].strip().split('|')]
for word in group.split(',')], key=lambda x: x[0]), key=lambda x: x[0])
for place, lines in [[a, ','.join(sorted(map(lambda x: x[1], b), key=int))]]]
"Bonus" #3: terminal-tables-because-I-got-fired-for-pissing-off-my-coworkers-so-I-have-free-time-edition v75.2
Note: requires terminaltables 3rd party library
#!/usr/bin/env python3.6
import io
import itertools
import re
import terminaltables
if __name__ == '__main__':
print(terminaltables.AsciiTable(
[['Places', 'Line No.'], *[[place, lines]
for a, b in itertools.groupby(sorted([[word, n]
for line in io.StringIO(open('f.txt').read())
for group, n in [re.subn('(\d*)\s*(.*)', '\g<2>|\g<1>', line, 1)[0].strip().split('|')]
for word in group.split(',')], key=lambda x: x[0]), key=lambda x: x[0])
for place, lines in [[a, ','.join(sorted(map(lambda x: x[1], b), key=int))]]]]).table)
output
+----------------+----------+
| Places | Line No. |
+----------------+----------+
| arsenal | 1,2,7 |
| atalanta | 7 |
| atletic bilbao | 9 |
| barcelona | 1,9 |
| bayern | 5 |
| celtic | 5 |
| chelsea | 1,2 |
| cska | 1,7 |
| dortmund | 5 |
| juventus | 2 |
| las palmas | 9 |
| milan | 2,9 |
| napoli | 2,5 |
| psg | 7 |
| real madrid | 1 |
+----------------+----------+