How to Determine Alphabetical Order in Python

by Veronica Summers

Python is an open-source programming language ideal for learning how to program, due to its easy-to-read programming syntax. A common Python programming task is sorting a list of items in alphabetical order. For example, you may need to sort a list of items that your company needs to purchase. To sort a list in alphabetical order, use Python's built-in "Sorted" function.

Step 1

Open your Python editor.

Step 2

Enter a list of items. For example, type: groceryList = ('apple', 'candy', 'berries', 'nuts')

Step 3

Sort the list using the "Sorted" function. Continuing the example, type the following: sorted (groceryList)

Press "Enter." Python sorts the list in alphabetical order. ['apple', 'berries', 'candy', 'nuts'] In the example above, Python sorts the strings in the variable, 'groceryList,' and returns a list, signified by brackets, containing the strings sorted in alphabetical order.


About the Author

Veronica Summers is an Internet pioneer, creating websites for Fortune 500 companies since 1994. In over 15 years of writing for the Web, she has received awards for explaining complex topics in an easy-to-read manner. Summers holds a Bachelor of Science in technical writing from Carnegie Mellon University. She writes computer- and travel-related articles online.

More Articles