Append Size


Regarding this problem:

I’m not aware that we’ve covered the “for” “in” function thus far?

The answer contains this line:

for i in range(1, len(lst) + 1):

I noticed another poster with a similar problem with this task but it seems the question has been reworded since.


The task can be accomplished without a for loop. While the following is not a complete solution to this exercise, it does illustrate an alternative strategy …

my_list = [3, 7, 4, 8]
my_list.extend(list(range(1, len(my_list) + 1)))

… however the authors do seem to be promoting the use of a for loop in this exercise.

A more comprehensive presentation of for loops is offered later on in Learn Python: Loops.


Thank you for your help