(Apr-28-2020, 01:24 PM)perfringo Wrote: As this is homework I will provide ways without for-loop. This may or may not give an ideas.
>>> d = {'ham': 7, 'spam': 42} >>> sum(d.values()) / len(d.values()) 24.5There is mean() in statistics module, so one can do:
>>> from statistics import mean >>> mean(d.values()) 24.5
Something like this came to my mind first, but i cant figure out working way that involves for, since that is what is asked for.
(Apr-28-2020, 10:56 AM)buran Wrote: please, show what have you tried in using for loop to iterate over dict values.
if you need you can check out tutorials section:
https://python-forum.io/Thread-for-loops
https://python-forum.io/Thread-Basic-Dictionaries
(Apr-28-2020, 12:33 PM)deanhystad Wrote: https://docs.python.org/3/tutorial/datas...ctionaries
Look under 5.6 Looping Techniques
And use better titles for your threads. "I'm a helpless newbie" type topics just make me want to ignore the post.
I guess i failed to find what i need in your links, but that stuff will come in handy for sure.
Is there a way i can change title thread?
Current state of things
dic={"123/2018":8,"124/2017":6,"125/2018":7,"126/2017":9} del dic["124/2017"] #ili recnik.pop("124/2017") dic["435/2018"]=6 print(dic) med=sum(dic.values())/len(dic) print(med)