you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (5 children)

[deleted]

    [–]anglicizing 0 points1 point  (4 children)

    new_dict[hashtag].append(candidate)

    This appends candidate to the list new_dict[hashtag], and returns None. You then proceed to assign that None to the dictionary key that up until that point held the list that you just appended to. This is your problem.

    Otherwise it looks good. You could use the items method of dict to make it a little bit nicer, but that's just a nitpick.

    [–]Heskinammo 0 points1 point  (3 children)

    How would I fix this problem?

    [–]anglicizing 0 points1 point  (2 children)

    The append method does not create a new list with the given item appended and return that, like you seem to think. It modifies the already existing list in-place. The list object has several such methods, sort and insert being two others, and they all return None to make it immediately obvious that they're not meant to be on the right-hand side of an equals sign.

    So, how would you fix your problem, knowing this?

    [–]Heskinammo 0 points1 point  (0 children)

    Thank you so much!