[Patches] [ python-Patches-825814 ] Add list.sorted()
SourceForge.net
noreply at sourceforge.net
Tue Oct 28 19:40:46 EST 2003
Patches item #825814, was opened at 2003-10-17 19:34
Message generated for change (Comment added) made by rhettinger
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=825814&group_id=5470
Category: Core (C code)
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: Raymond Hettinger (rhettinger)
>Assigned to: Alex Martelli (aleax)
>Summary: Add list.sorted()
Initial Comment:
As discussed on py-dev, this returns a sorted copy of a
list while leaving the original intact.
----------------------------------------------------------------------
>Comment By: Raymond Hettinger (rhettinger)
Date: 2003-10-28 19:40
Message:
Logged In: YES
user_id=80475
Alex, can you give this patch a second review.
I did not put in additional classmethod warnings because all
plausible misunderstandings raise an error anyway.
----------------------------------------------------------------------
Comment By: Raymond Hettinger (rhettinger)
Date: 2003-10-18 12:41
Message:
Logged In: YES
user_id=80475
Rationale for the change
---------------------
An inline sort is usable anywhere an expression is allowed.
This includes important places like function call arguments
and list comprehensions:
todo = [t for t in tasks.copysort() if due_today(t)]
genhistory(date, events.copysort(key=incidenttime))
Spreading these out over multiple lines is an unnecessary
distractor from the problem domain, making the code harder
to understand and maintain.
Also, using copysort() eliminates a unnecessary variable
that changes state from unsorted to sorted and has a
lifetime longer than the data is actually needed. In longer
code fragments, this decreases code complexity, code length,
the number of variables, and decreases the risk of using a
variable in the wrong state which is a common source of
programming errors.
----------------------------------------------------------------------
Comment By: Raymond Hettinger (rhettinger)
Date: 2003-10-18 01:26
Message:
Logged In: YES
user_id=80475
Revised the patch to avoid an unnecessary copy whenever the
underlying object is not referenced anywhere else -- this
occurs in the common use case: for elem in
d.keys().copysort(): . . .
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=825814&group_id=5470
More information about the Patches
mailing list