+ 1
On numbered list
On python for kids, I saw a question like this. list=["yams","eggs","pepper"] create a loop that prints out the list(including the numbers) 1 yams 2 eggs 3 pepper Been racking my brains
14 Answers
+ 3
this should work
for i in range(len(list)):
print(i+1,list[i])
+ 3
try this, it should work as you looking for.
list=["yams","eggs","pepper"]
for c,v in enumerate(list,1):
print(c,v)
+ 1
realcosmos ,racking your brain is the fun part, no?
Do you know how to print the list without the numbers?
+ 1
Use enumerate insted of range and len! range and len looks ugly.
+ 1
unpacking is like breaking iterable types (tuples, lists, dicts...)and assigning them to variables.
example: a, b = [2, 3] ... a+b will be 5
each result of enumerate(list) is a paired tuple (number, list item).
try to unpack your i...
+ 1
nice Saga.
so many options
3 different ways to go at this thing.
thanks everyone
+ 1
thanks qwertiony.
hmm
print (*i)😅😅😅😅😅
0
yup
for i in list:
print(i)
0
thanks Davy. I understand up to the print i+1, but the list [i] part is confusing. can you clarify?
modified
I got it
it specifies the index of the item on the list to be printed.
0
thanks qwertiony.
that's a new one to me.
for i in enumerate(list, 1):
print (i)
except the output comes with parentheses, commas, and quotation marks.☺
0
do you know what is unpacking?
0
no.
0
saga just ruined next step :(
SagaTheGreat 💯 , can you explain nested unpacking?
0
Qwertiony here you will get idea about that,
https://dbader.org/blog/JUMP_LINK__&&__python__&&__JUMP_LINK-nested-unpacking