Append Size


#1

Regarding this problem:

https://www.codecademy.com/paths/computer-science/tracks/cspath-flow-data-iteration/modules/dspath-lists/lessons/python-functions-lists-cc/exercises/append-size

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.


#2

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)))
print(my_list)

… 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.


#3

Thank you for your help