very good reasons?

Kragen Sitaker kragen at dnaco.net
Sat Sep 30 22:53:58 EDT 2000


In article <8r2k0n01u30 at drn.newsguy.com>,
Grant Griffin  <g2 at seebelow.org> wrote:
>I was trying to chain "sort" and "reverse" together the other day <<confess>>,
>ala Perl, but I found that it didn't work . . .
>I would have expected sort and reverse to return the list in question, but
>instead they return None.  So I had to do something like:

If you want Perl, you know where to find it: in Python!  Here's how:

def sort(x):
	y = list(x)
	y.sort()
	return y

def reverse(x):
	y = list(x)
	y.reverse()
	return y

>>> y
[1, 2, 17, 4, 5]
>>> reverse(sort(y))
[17, 5, 4, 2, 1]

The Python way is probably clearer and more efficient, though.

>Likewise, I wondered the other day why "real" and "imag" are "attributes" of
>complex numbers instead of functions: [but you can't set them]

Complex numbers are immutable.  Dunno why.  Maybe so they're like other
numbers.

By the way, what's a Iowegian, and how do you pronounce it?
-- 
<kragen at pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
Perilous to all of us are the devices of an art deeper than we ourselves
possess.
                -- Gandalf the Grey [J.R.R. Tolkien, "Lord of the Rings"]





More information about the Python-list mailing list