Given this code:
import random
plusMin = [1000, -47, 1000, -250, 1015, -63, 1000, -563]
masterList = []
subset = [-125, 375, 250, 250]
for item in plusMin:
if item > 0:
masterList.append(subset)
subset.append(1)
else:
masterList.append(item)
print masterList
Shouldn't the following output?
[[-125, 375, 250, 250], -47, [-125, 375, 250, 250, 1], -250, [-125, 375, 250, 250, 1, 1], -63, [-125, 375, 250, 250, 1, 1, 1], -563]
...appending a "1" to the subset with each repetition of the for loop?
Instead the output I get is:
[[-125, 375, 250, 250, 1, 1, 1, 1], -47, [-125, 375, 250, 250, 1, 1, 1, 1], -250, [-125, 375, 250, 250, 1, 1, 1, 1], -63, [-125, 375, 250, 250, 1, 1, 1, 1], -563]
which looks like the output from nested for loops. Why on earth am I getting four "1" appended to the end of subset with the very first item in the for loop?
Thanks!