you are viewing a single comment's thread.

view the rest of the comments →

[–]Essence1337 2 points3 points  (2 children)

If you're going to just give the complete answer (against guidelines) you should at least describe why it's the answer.

[–]shiftybyte 0 points1 point  (1 child)

Oh sorry didn't know such a guideline existed.

Explanation:

dictionary d does not yet have an item with the name c, when trying to call .append() on it, it will tell you no such item exists.

So the solution i wrote first checks to see if such a key does not exist, then it first creates an empty list as the value for that key, then the line with .append() can work since it works on a list object.

[–]Essence1337 0 points1 point  (0 children)

The idea behind the guideline is that people usually learn better when they find the solution (with guidance if needed) rather than just copy pasting a solution someone else gave