Do int.__lt__/__gt__/etc. exist?

C

Chris Dutton

I'm just curious. I've been trying to demonstrate functional thinking
in Python, but I can't find these methods for int objects. It would be
immensely helpful for something like:

filter(4 .__lt__, range(10))

As opposed to:

filter(lambda a: 4 < a, range(10))
 
G

Guest

I'm just curious. I've been trying to demonstrate functional thinking
in Python, but I can't find these methods for int objects. It would be
immensely helpful for something like:

filter(4 .__lt__, range(10))

As opposed to:

filter(lambda a: 4 < a, range(10))

Python is neither pure object nor pure functional language. There is an
"operator" module, with its operator.lt, but it is not exactly what you need.
You still need lambda with it.

The recommended way to do what you want is

result = [x for x in xrange(10) if 4 < x]
 
T

Terry Reedy

Chris Dutton said:
I'm just curious. I've been trying to demonstrate functional thinking
in Python, but I can't find these methods for int objects. It would be
immensely helpful for something like:

filter(4 .__lt__, range(10))

Do dir(int) and you will find that int has .__cmp__ but not the individual
compares (at least in 2.2).

tjr
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,264
Messages
2,571,315
Members
48,000
Latest member
SusannahSt

Latest Threads

Top