Python Forum
average of values in dict with use of for
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
average of values in dict with use of for
#4
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.5
There is mean() in statistics module, so one can do:

>>> from statistics import mean
>>> mean(d.values())
24.5
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
RE: Thread opened by a newbie - by buran - Apr-28-2020, 10:56 AM
RE: Thread opened by a newbie - by deanhystad - Apr-28-2020, 12:33 PM
RE: Thread opened by a newbie - by perfringo - Apr-28-2020, 01:24 PM
RE: Thread opened by a newbie - by Daromir - Apr-28-2020, 05:09 PM
RE: Thread opened by a newbie - by perfringo - Apr-29-2020, 05:26 AM
RE: Thread opened by a newbie - by deanhystad - Apr-28-2020, 05:52 PM
RE: Thread opened by a newbie - by Daromir - Apr-28-2020, 06:00 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020