Fluxriflex Fluxriflex - 1 year ago 89
Python Question

How to print out a numbered list in Python 3

So anyway, I'm working with lists in python, and I need to figure out how to print out the index location of each item (+1, so it starts at 1 instead of 0) alongside the each individual item in the list. Here's an idea of what I want it to look like:

blob = ["a", "b", "c", "d", "e", "f"]
for i in blob:


1 a
2 b
3 c
4 d
5 e

So anyway, what I need to know is how do I get those numbers to show up alongside what I'm trying to print out? I can get a-e printed out no problem, but I can't figure out how to number the list. Anyway, any help would be greatly appreciated! Thank you in advance!

Answer Source
for a, b in enumerate(blob, 1):
    print '{} {}'.format(a, b)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download