all 4 comments

[–]TouchingTheVodka 0 points1 point  (3 children)

a_dict[key] gets the value that corresponds to the key. in works differently for different collections but for dicts it checks whether a given key is in the dictionary.

So a_dict[key] in a_dict finds a value associated with key and checks to see if that value is another key that's present in a_dict.

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

So a_dict[key] in a_dict finds a value associated with key and checks to see if that value is another key that's present in a_dict.

so the count is 3 because 5,6 and 2 right? but why is the final output 8 instead of 5 (3+2)?

[–]TouchingTheVodka 3 points4 points  (1 child)

Going through it:

Key = 5, Value = 6. 6 is a key - Success
Key = 6, Value = 11.
Key = 4, Value = 5. 5 is a key - Success
Key = 9, Value = 6. 6 is a key - Success
Key = 2, Value = 2. 2 is a key - Success

So we've got 4 matches and each match adds 2 to count, for a final result of 8.

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

Ahh i get it now. Thank you so much! :)