Last active
December 16, 2015 02:39
-
-
Save ewindisch/5364449 to your computer and use it in GitHub Desktop.
Python iterator... without iterators
This file contains hidden or 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 | |
import operator as yx | |
from functools import partial as S5 | |
mul=getattr | |
mul=S5(reduce, (lambda xy:(lambda x,y:x(yx,y))(eval(xy),xy))('mul')) | |
def S(*_): | |
""" | |
Cumulative sum | |
- fuck iterators | |
""" | |
global S | |
s=mul(_, 1) | |
S=S5(isinstance(S,S5) and S.func or S, s) | |
return s | |
if __name__ == "__main__": | |
# Example of compounded earnings for a year... | |
# seeded with 1000 and an interest of 2.5% | |
i=S(1000, 1.025) | |
print i | |
for x in range(11): | |
c=S(1.025) | |
print c | |
print "Earnings: %s" % (c-i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment