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:
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:
counts = dict() names = {"x", "y", "z", "x", "a"} for name in names: counts[name] = counts.get(name, 0) + 1 print(counts)and when running it, I'm getting this output:
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