Created
November 19, 2010 04:18
-
-
Save gregglind/706115 to your computer and use it in GitHub Desktop.
Showing some raw python, if there were no classes...
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
## python without classes? | |
def newlist(items): | |
def in_(item): | |
return item in items | |
def index(a): | |
return items.index(a) | |
def pretty(): | |
for x in items: | |
print x | |
# python needs the symbols defined | |
# before we reference them | |
methods = { | |
'in_': in_, | |
'index': index, | |
'pretty': pretty, | |
} | |
return methods | |
L = newlist(['a','b','c','d']) | |
assert L['in_']('a') == True | |
assert L['index']('c') == 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment