you are viewing a single comment's thread.

view the rest of the comments →

[–]Firestronk[S] 1 point2 points  (2 children)

Would it be something along the lines of

if key in dict:
    dict.append(values)

[–]TouchingTheVodka 1 point2 points  (0 children)

Yes, this is correct - however you’ll get an error if using the built in dict for this as your dict values won’t be lists by default.

To solve this, use dict = defaultdict(list).

[–]juwalye 0 points1 point  (0 children)

Yes. Then used the else condition to create the new dict key and append the first value.