My first ever Python program, comments welcome
Dave Angel
d at davea.name
Sat Jul 21 22:01:42 EDT 2012
On 07/21/2012 09:56 PM, MRAB wrote:
> On 22/07/2012 01:32, Steven D'Aprano wrote:
>> On Sat, 21 Jul 2012 20:40:46 +0100, MRAB wrote:
>>
>>> On 21/07/2012 20:08, Lipska the Kat wrote:
>>>> l=sorted(l, key=itemgetter(0))
>>>
>>> Short is:
>>>
>>> l.sort(key=itemgetter(0))
>>
>> Shorter, and the semantics are subtly different.
>>
>> The sorted function returns a copy of the input list.
>>
>> The list.sort method sorts the list in place.
>>
> Since the result is bound to the original name, the
> result is the same.
>
In this particular program, yes. But if there's another variable bound
to the same list, then the fact that there's a new object from sorted()
makes a difference.
--
DaveA
More information about the Python-list
mailing list