How to Determine Alphabetical Order in Python

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.

Instructions

    • 1

      Open your Python editor.

    • 2

      Enter a list of items. For example, type:

      groceryList = ('apple', 'candy', 'berries', 'nuts')

    • 3

      Sort the list using the "Sorted" function. Continuing the example, type the following:

      sorted (groceryList)

    • 4

      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.

Related Searches:

References

Comments

Related Ads

Featured