blessed be Guido, for "5 <= X <= 10" does what it should...

Brian Kelley kelley at bioreason.com
Tue Apr 4 16:40:33 CEST 2000


> Here's a Hack for the Mighty Pythonista to consider: Can you construct a
> program that you can call like this:
>
>     test_transitive( 0,100, '<=', 5 ) # generate a<=b<=c<=d<=e for range
> 0..100
>

A fun one here's the short version( it doesn't use the 5 limit):

import string
def test_transitive(start, end, compareString):
  return eval( string.join( map(str, range(start,end)), compareString ) )

A little obtuse, eh?

range(0,5) == [0,1,2,3,4]
map(str, range(0,5)) == ['0', '1', '2', '3', '4']
string.join(map(str,range(0,5)), ">") == "0>1>2>3>4"
eval(string.join(map(str,range(0,5)), ">")) == 1

I like python...

>
> Anyways, blessed be Guido, for near as I can figure it, he hath got it
> right! :-)
>
> Warren

--
Brian Kelley          (505) 982-7884 ext 207
Bioreason, Inc        kelley at bioreason.com
105 Washington #303, Santa Fe NM, 87501





More information about the Python-list mailing list