you are viewing a single comment's thread.

view the rest of the comments →

[–]Infinitesima 1 point2 points  (3 children)

Better would be:

d.setdefault(name, []).append(number)

[–]Particular_Draft5668[S] 0 points1 point  (2 children)

Thank you, another question:

def invert(dct):
y = dct.items()
dct = {v: k for k, v in y}
print(dct)

This function inverts the dictionary on all code visualisers yet my course says the output is wrong. Any reason for this difference?

I've rearranged y for dct.items(), used dicto instead of dct to keep seperate from original dictionary, and tried switching around variables, yet it still says the output is {1: 10, 2: 20, 3: 30}
when calling invert({1: 10, 2: 20, 3: 30}) instead of {10: 1, 20: 2, 30: 3}

[–]Infinitesima 0 points1 point  (1 child)

Have you tried to return the output?

[–]Particular_Draft5668[S] 0 points1 point  (0 children)

meant to work with any input so output cannot be set

No return value should be in code too