- 1

words = ["hello", "world", "spam", "eggs"] counter = 0 max_index = len(words) - 1 while counter <= max_index: word = words[

can anyone explain me the need of line no 5 i,e word=words[counter] in the above example in an easier way plz m a beginner

29th Jan 2017, 7:09 PM
kumar badal
kumar badal - avatar
2 Antworten
0
We iterate over a list. Word value will be hello at first iter, world at second iter... and so one.
29th Jan 2017, 7:43 PM
Leshark
Leshark - avatar
0
Is the following line counter += 1 or counter = counter + 1? If so whats happening is that word = words[counter] Counter will represent the index number starting from 0, index meaning the item number from the list... Until it reached the length of that max_length variable an item from words will return to the variable word
30th Jan 2017, 2:41 AM
admani1010