Skip to content

Instantly share code, notes, and snippets.

@g-leech
Created March 11, 2021 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save g-leech/075f47dcf6a66508dbd380b56961b8c8 to your computer and use it in GitHub Desktop.
Save g-leech/075f47dcf6a66508dbd380b56961b8c8 to your computer and use it in GitHub Desktop.
budget = 100
names = ["A", "B", "Best", "Pricey"]
prices = [100, 10, 1, 101]
volumes = [10, 1, 0.1, 100] # litres
abvs = [1, 10, 100, 100] # %
for i, p in enumerate(prices) :
if p > budget:
del names[i]
del prices[i]
del volumes[i]
del abvs[i]
units = [ v * p for v,p in zip(volumes, abvs) ]
bangforbuck = [ u / p for u,p in zip(units, prices)]
i = max(zip(bangforbuck, range(len(bangforbuck))))[1]
print(names[i])
print("Units per €:", bangforbuck[i], "units")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment