[Tutor] If tuple cannot be sorted, then why sorted() on a tuple is fine?

Mats Wichmann mats at wichmann.us
Wed Aug 2 15:22:13 EDT 2017


it generated a new object, did not change the original. hint: notice the output is a list, not a tuple!

On August 2, 2017 1:01:31 PM MDT, C W <tmrsg11 at gmail.com> wrote:
>Dear list,
>
>I am a little confused about why Tuple can be sorted.
>
>Suppose I have the following,
>
>> aTuple = (9, 3, 7, 5)
>> sorted(aTuple)
>[3, 5, 7, 9]
>
>Why is it ok to sort a the class tuple? If it is invariant by nature,
>then
>wouldn't applying a function on it yield an error?
>
>Thanks!
>_______________________________________________
>Tutor maillist  -  Tutor at python.org
>To unsubscribe or change subscription options:
>https://mail.python.org/mailman/listinfo/tutor

-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.


More information about the Tutor mailing list