Here's my code:
`tv_dict = {}
user_input = input()
file_open = open(user_input)
file_content = file_open.readlines()
new_content = []
for x in file_content:
new_content.append(x.strip())
list_len = len(new_content) // 2
loop_cy = 1
k = -1
v = -2
while loop_cy <= list_len:
key = new_content[k]
value = new_content[v]
tv_dict[key] = value
k += 2
v += 2
loop_cy += 1
val_sort1 = {k:[v for v in tv_dict.keys() if tv_dict[v] == k] for k in set(tv_dict.values())}
val_sort2 = dict(sorted(val_sort1.items(), key=lambda val:val[0]))
file_1a = ''.join("{}: {}\n".format(k, v) for k, v in val_sort2.items())
print(file_1a)`
I'm trying to print:
10: Will & Grace
12: Murder, She Wrote
14: Dallas
20: Gunsmoke, Law & Order
30: The Simpsons
But I'm getting:
10: ['Will & Grace']
12: ['Murder, She Wrote']
14: ['Dallas']
20: ['Gunsmoke', 'Law & Order']
30: ['The Simpsons']
NOTE: The dictionary keys MUST be outputted together if they have the same value. (As seen with Gunsmoke and Law and Order)
I can get:
10: Will & Grace
12: Murder, She Wrote
14: Dallas
20: Gunsmoke
20: Law & Order
30: The Simpsons
But sorting by values brings back the brackets and quotes.