By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,427 Members | 1,379 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,427 IT Pros & Developers. It's quick & easy.

Do int.__lt__/__gt__/etc. exist?

P: n/a
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))
Sep 7 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Wed, 07 Sep 2005 00:02:49 GMT
Chris Dutton wrote:
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]

--
jk
Sep 7 '05 #2

P: n/a

"Chris Dutton" <cd*****@gmail.com> wrote in message
news:J6qTe.120678$Hk.14664@pd7tw1no...
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

Sep 7 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.