Never alter a list while iterating it. Use list comprehension instead, like this
start_list = [5, 3, 1, 2, 4]
print [x**2 for x in start_list]
# [25, 9, 1, 4, 16]
Actually, you are doing something like this
start_list = [5, 3, 1, 2, 4]
for item in start_list:
start_list.append(item ** 2)
Lets put some print
statements and understand what happens when you execute the code
start_list = [5, 3, 1, 2, 4]
for item in start_list:
start_list.append(item ** 2)
print len(start_list), start_list
if len(start_list) == 15:
break
Output
6 [5, 3, 1, 2, 4, 25]
7 [5, 3, 1, 2, 4, 25, 9]
8 [5, 3, 1, 2, 4, 25, 9, 1]
9 [5, 3, 1, 2, 4, 25, 9, 1, 4]
10 [5, 3, 1, 2, 4, 25, 9, 1, 4, 16]
11 [5, 3, 1, 2, 4, 25, 9, 1, 4, 16, 625]
12 [5, 3, 1, 2, 4, 25, 9, 1, 4, 16, 625, 81]
13 [5, 3, 1, 2, 4, 25, 9, 1, 4, 16, 625, 81, 1]
14 [5, 3, 1, 2, 4, 25, 9, 1, 4, 16, 625, 81, 1, 16]
15 [5, 3, 1, 2, 4, 25, 9, 1, 4, 16, 625, 81, 1, 16, 256]
You are basically growing the list on every iteration by appending to it. That is why your program is in infinite loop.