[Tutor] sorted function

shubham goyal skgoyal721 at gmail.com
Sat Apr 15 02:35:51 EDT 2017


Thankyou. got it.

On Sat, Apr 15, 2017 at 5:44 AM, Steven D'Aprano <steve at pearwood.info>
wrote:

> On Fri, Apr 14, 2017 at 11:59:25PM +0530, shubham goyal wrote:
>
> >   sorted(ls)
> >   sorted(ls1)
>
> Here you sort ls and throw the result away, then you do the same to ls1.
>
> sorted() makes a copy of the list and sorts it. You need to write:
>
> ls = sorted(ls)
> ls1 = sorted(ls1)
>
> but even better would be to sort in place:
>
> ls.sort()
> ls1.sort()
>
> which doesn't make a copy.
>
>
>
> --
> Steve
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>


More information about the Tutor mailing list