Skip to content

Instantly share code, notes, and snippets.

@ewindisch
Last active December 16, 2015 02:39
Show Gist options
  • Save ewindisch/5364449 to your computer and use it in GitHub Desktop.
Save ewindisch/5364449 to your computer and use it in GitHub Desktop.
Python iterator... without iterators
#!/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