Skip to content

Instantly share code, notes, and snippets.

@adrianp
Last active October 1, 2015 01:28
Show Gist options
  • Save adrianp/1894953 to your computer and use it in GitHub Desktop.
Save adrianp/1894953 to your computer and use it in GitHub Desktop.
Comparing a list with a function in Python
"""Some Python code to illustrate the 'issue' noticed in JavaScript here:
http://stackoverflow.com/questions/9381321/a-function-is-larger-than-an-array
This will work on Python 2.x; in Python 3.x you would get:
TypeError: unorderable types: list() > function()
"""
l1 = []
def f():
return 0
l2 = []
print l1 > f # True
print f > l1 # False
print str(l1) > str(f) # True, same as line 15
print str(f) > str(l1) # False, same as line 16
print l2 > f # True
print f > l2 # False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment