I'm a newbie to Python. I'm writing a very simple piece of code to print the contents of a list using 'for' loop with .format()
and I want the output as below, but I'm getting this error:
names = ['David', 'Peter', 'Michael', 'John', 'Bob']
for i in names:
print("{}.{}".format(i, names[i]))
print("{}.{}".format(i,breakfastMenu[i]))
TypeError: list indices must be integers or slices, not str
Expected output I want: 1. David 2. Peter 3. Michael 4. John 5. Bob
Can someone please help me to get that output?