It's agreed upon that the iterable item in a for loop is evaluated only once. Hence, the output f called is printed once.
What I'm struggling to figure out is, why am I not getting an out-of-bound error? Since at the time of the evaluation, the length was equal to 100.
mylist = [x for x in range(100)]
def printmylist(thelist):
print("f called")
return thelist
for i, item in enumerate(printmylist(mylist)):
print(len(mylist))
del mylist[len(mylist) - i - 1]
f called 100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51