Skip to content

Instantly share code, notes, and snippets.

@islandjoe
Created June 13, 2021 06:25
Show Gist options
  • Save islandjoe/8ec8009aa75f3fd1505bcb728904ff40 to your computer and use it in GitHub Desktop.
Save islandjoe/8ec8009aa75f3fd1505bcb728904ff40 to your computer and use it in GitHub Desktop.
Python Exercises: Get the min, avg, and max of a list of numbers
figures = [79250913.5716, 48142828.4666, 41386999.2223, 93411238.6832, 15514669.4931, 70598005.1982, 33304295.9951, 75789282.3759, 74542259.467, 20922976.4366, 42697744.5193, 43535355.1567]
from statistics import median
min_stat, max_stat, avg_stat = min(figures), max(figures), median(figures)
print(f"min: {min_stat}\nmax: {max_stat}\navg: {avg_stat}")
min: 15514669.4931
max: 93411238.6832
avg: 45839091.81165
from itertools import tee
from statistics import median
min_stat, max_stat, avg_stat = tee(figures, 3)
print(f"min: {min(min_stat)}\nmax: {max(max_stat)}\navg: {median(avg_stat)}")
min: 15514669.4931
max: 93411238.6832
avg: 45839091.81165
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment