Hi,
I've only been learning to code for a couple of weeks now. This is my first post. If I've posted incorrectly please do let me know.
So, I'vebeen typing this code:
and when running it, I'm getting this output:
Thank you
I've only been learning to code for a couple of weeks now. This is my first post. If I've posted incorrectly please do let me know.
So, I'vebeen typing this code:
1 2 3 4 5 |
counts = dict () names = { "x" , "y" , "z" , "x" , "a" } for name in names: counts[name] = counts.get(name, 0 ) + 1 print (counts) |
Output:D:\Python\helloworld\venv\Scripts\python.exe D:/Python/helloworld/app.py
{'a': 1, 'z': 1, 'x': 1, 'y': 1}
Process finished with exit code 0
Why isn't the code correctly counting the number of values in the "names" variable?Thank you