very good reasons?
Bjorn Pettersen
bjorn at roguewave.com
Fri Sep 29 16:10:14 EDT 2000
Grant Griffin wrote:
>
> Hi Gang,
>
> I was trying to chain "sort" and "reverse" together the other day <<confess>>,
> ala Perl, but I found that it didn't work, e.g.:
>
> Python 2.0b2 (#6, Sep 26 2000, 14:59:21) [MSC 32 bit (Intel)] on win32
> >>> a=[1,2,3,4]
> >>> b=a.sort().reverse()
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> AttributeError: 'None' object has no attribute 'reverse'
> >>> c=a.sort()
> >>> repr(c)
> 'None'
>
> I would have expected sort and reverse to return the list in question, but
> instead they return None.
That's because sort is inefficient on very big lists (it takes over
9/100 seconds to sort a 20,000 item list of floating point numbers!).
Since we know it's so slow, we wouldn't want you to write code like "for
i in a.sort()" without having to jump through some loops... It's the
same reason why shelves don't have an items() method.
<wink?>
-- bjorn
More information about the Python-list
mailing list