Not keyword with dictionary

Hello,
I had a question in the “Python Data Analysis Basics” Mission on Page 4.
URL:Learn data science with Python and R projects

The correct code is:
decade_frequency = {}

for d in decades:
if d not in decade_frequency:
decade_frequency[d] = 1
else:
decade_frequency[d] += 1

My code was:
decade_frequency={}
for decade in decades:
if decade in decade_frequency:
decade_frequency[decade] += 1
else:
decade_frequency[decade] =1

I looked back at previous missions, and unless I missed it, this was the first time I’ve seen the “not” keyword used. Other than it was a part of the instructions, why was “not” keyword used here? Why didn’t we write the code for this dictionary like in previous missions.

1 Like

Hi again, Mike,

These 2 pieces of code are absolutely identical. You can use any of them to receive the same result.

1 Like

Hi (again!) @Elena_Kosourova,
Thanks so much!

1 Like

@mtl1212 You can create code blocks by wrapping triple backticks (each on their own line). Currently, the indentation is off.
Here’s guidelines to asking question: Guidelines for asking a technical question in our Community

1 Like

Hi @hanqi,
Thank you for the advice. I put the the 3 backticks on the first line and last line of code, i.e.:
(3 backticks) code
code
code (3 backticks)

However, it was aggravating trying to write after it (I couldn’t get out of that box). So, I went to one backtick, however, I couldn’t indent using the one backtick. Now that I know the 3 backticks go on their own separate line I’ll use this going forward.