[Tutor] R?p. : Sorting Data in Databases

Albert Sweigart asweigart at gmail.com
Tue Nov 24 03:54:41 CET 2009


Ken,

You should probably use the sorting functionality that your DBMS
provides. However, if you have a list of strings that end with a new
line and start with an apostrophe, you can use list comprehensions to
remove them:

newlist = [x[1:-1] for x in newlist]

You can look at the following links to find out more about list
comprehensions here:

http://www.secnetix.de/olli/Python/list_comprehensions.hawk
http://www.network-theory.co.uk/docs/pytut/ListComprehensions.html

-Al
You should check out my free beginner's Python book here:
http://inventwithpython.com


> Actually, I was fooling around with that today by adding to the list
> from the file and then sort.  I was using the following simplify method:
>
> newlist = []
>
> newlist = [
>    456, 54, 8, 158, 878
>    ]
> (above data read from file)
>
> newlist.sort()
>
> print newlist
> [8, 54, 158,  456, 878]
>
> (still working adding to new file]
>
> The actual sorted list has, as I recall, an apostrophe at the beginning
> and an \n at the end of every number I had.  I will be working on that.
>
> Thanks for your suggestion.
>
> Ken
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <http://mail.python.org/pipermail/tutor/attachments/20091123/fb03a325/attachment.htm>
>
> ------------------------------
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
> End of Tutor Digest, Vol 69, Issue 105
> **************************************
>


More information about the Tutor mailing list