C2 W2 Assignment Error in preloaded Code - please help

There is an issue with the sort in function ‘create_transition_matrix’ in C2W2 Assignment exercise 3, please see screenshots.

Fixing the code to:
all_tags = sorted([str(tag) for tag in tag_counts.keys()])
changes the order of sorting and the output results thus causing test to fail.
I’d really appreciate help asap as changing the sorting order seems to screw up all the tests in the following exercises. So it’s critical.

Thank you very much!

1 Like

No the problem is not there (I just ran it), but the problem should be when you produce the tag_counts in exercise 1; def create_dictionaries(training_corpus, vocab).

Make sure you produce the right type of tag_counts

tag_counts: a dictionary where the keys are the tags and the values are the counts


oh, I see, thank you. This line was creating extra keys:
tag_counts[tag] += 1

So it seems that one cannot use this shorthand for incrementing values of a dictionary. This version fixed the problem
tag_counts[tag] = tag_counts[tag] + 1
thanks very much for your help!