You can find the average of all keys in a map (dictionary) in python by using the sum
and len
functions. Here's an example:
main.py136 chars6 lines
This code will output:
main.py21 chars2 lines
Note: In python 3.x, the keys()
method returns a dictionary view object, which is iterable but not a list. So, we use the sum
function to sum up all the keys and then divide by the length of the dictionary to find the average.
gistlibby LogSnag