Simple yet confusing question?!

How are these different(different outputs)!??!?!??! ( the bottom one is the correct one!
dic={}
for i in words:
if i not in dic:
dic[i]=0
else:
dic[i] += 1
VERSUS
dic={}
for i in words:
if i not in dic:
dic[i]=0

dic[i] += 1

Hi!

Welcome to the forums :slight_smile:

Make sure to format the code in your posts when you ask questions because this makes it more readable and also often affects how your code would work (like in python):

First press the Screen Shot 2021-01-03 at 1.42.27 PM button and then paste the code between the tick marks Screen Shot 2021-01-03 at 1.42.33 PM

Also note if you type python in your terminal you can test how python works interactively (there’s an online shell for this as well here:Welcome to Python.org)

Thank You for your reply, I will take into account of the things you have mentioned!