Thursday, November 14, 2013

A Quick Tip - Alphabetical Order

     As I was looking through one of my old list articles, I realized that there's a function I don't remember writing about. This function is known as sort().

     Sort() is a function that sorts all items in a list in alphabetical order. Isn't that neat? Let's show an example of this. If you need to sort a bunch of words in alphabetical order, you can do it in a snap! Let's make a list:

words=['Exuberant', 'Philosophy', 'Pterodactyl', 'Potato', 'Avenue', 'Boulevard', 'Rendezvous', 'Embryonic']

     (Yes, those are real words)
     So, we use sort() like this:

words.sort()

     Now, let's print(words):

['Avenue', 'Boulevard', 'Embryonic', 'Exuberant', 'Philosophy', 'Potato', 'Pterodactyl', 'Rendezvous']

     Takes the pressure of of things, eh? Now I know you know the sort() function. Sorry it took so long to figure out that I didn't tell you this earlier!

No comments:

Post a Comment