How to Use enumerate() to Print a Numbered List in Python

You have a list of items and want to print it out as a numbered list using Python.

Starting List

fruit = ['banana', 'apple', 'pear', 'peach']

Desired Output

  1. banana
  2. apple
  3. pear
  4. peach

In another programming language, you might create a variable called i or num and then loop through the list incrementing the variable value by 1 with each iteration.

In Python, you use enumerate():

fruit = ['banana', 'apple', 'pear', 'peach']
for i, item in enumerate(fruit,1):
    print(i, '. ' + item, sep='',end='')

How enumerate() Works

The enumerate(iterable, start) function will return a sequence of tuples. If we loop through that sequence normally like this, we get a tuple on each iteration:

for t in enumerate(iterable):
    print(t) #t is a tuple

But the syntax we showed above unpacks that tuple on each iteration, so:

for a, b in enumerate(iterable):
    print(a) #first value in the tuple (the count)
    print(b) #second value in the tuple (the item in the original iterable)
Author: Nat Dunn

Nat Dunn is the founder of Webucator (, a company that has provided training for tens of thousands of students from thousands of organizations. Nat started the company in 2003 to combine his passion for technical training with his business expertise, and to help companies benefit from both. His previous experience was in sales, business and technical training, and management. Nat has an MBA from Harvard Business School and a BA in International Relations from Pomona College.

Follow Nat on Twitter at @natdunn and Webucator at @webucator.

About Webucator

Webucator provides instructor-led training to students throughout the US and Canada. We have trained over 90,000 students from over 16,000 organizations on technologies such as Microsoft ASP.NET, Microsoft Office, Azure, Windows, Java, Adobe, Python, SQL, JavaScript, Angular and much more. Check out our complete course catalog.