Last active
October 23, 2017 15:30
-
-
Save mie00/060233cb610bd0d3a8763ec43deb292e to your computer and use it in GitHub Desktop.
For bills and stuff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
def calc(gross, delivery, d): | |
""" | |
usage: | |
>>> calc(120, 9, { | |
'Ashraf': 40, | |
'Thabet': 20, | |
'Awadi': 20, | |
'Ghanem': 20, | |
}) | |
net: 100 | |
Ghanem: 24.5 | |
Thabet: 24.5 | |
Ashraf: 46.5 | |
Awadi: 24.5 | |
total: 120.0 | |
""" | |
s = sum(map(lambda (x, y): y, d.items())) | |
a2 = [(name, (lambda x:int(x) + [0,0.5,0.5,1][int(4 * (x % 1))])(i * 1.0 * (gross - delivery) / s + 1.0 * delivery / len(d))) for (name, i) in d.items()] | |
print("net: %s"%(s)) | |
print('\n'.join(map(lambda (x, y): '%s: %s'%(x, y), a2))) | |
print('total: %s'%sum(map(lambda (x, y):y, a2))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated to use keyword arguments instead, it won't accept duplicated entries as passing a dict, and of course less typing 😆
https://gist.github.com/abom/db0f8c66782ee91939226b80a6a1397d
I was wondering what is wrong, at the end it was a duplicated dict item.