[Tutor] Sorting a list in ascending order

isaac tetteh itetteh34 at hotmail.com
Fri Apr 29 16:29:54 EDT 2016


You can use sorted(line) but you result will be in a list if thats okay. Otherwise you can iterate the list. 

Sent from my iPhone

> On Apr 29, 2016, at 3:03 PM, Ken G. <beachkidken at gmail.com> wrote:
> 
> In entering five random number, how can I best sort
> it into ascending order, such as 0511414453? Using
> Linux 2.7.6 in Ubuntu 14.04.4. Thanks.
> 
> number01 = "41"
> number02 = "11"
> number03 = "05"
> number04 = "53"
> number05 = "44"
> line = number01 + number02 + number03 + number04 + number05
> print
> print line
> line.sort()
> print
> print line
> 
> 
> 4111055344
> 
> Traceback (most recent call last):
>  File "Mega_Millions_01_Tickets_Entry_TEST_TEST.py", line 11, in <module>
>    print line.sort()
> 
> AttributeError: 'str' object has no attribute 'sort'
> 
> 
> _______________________________________________
> 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