I have a really weird problem with append in a list.
import random
def CreatePopulation(a, r):
pippo=range(a)
print pippo
i=0
prova=[]
while i<r:
random.shuffle(pippo)
print pippo
prova.append(pippo)
print prova
i=i+1
return prova
pop=CreatePopulation(5,10)
print pop
example=["a","b"]
example.append("c")
print example
I can't upload the entire output because the website says that it's bad formatted. But the output it's a list with ten times the same value, the last shuffle of x, like this:
[[1, 0, 4, 2, 3], [1, 0, 4, 2, 3], [1, 0, 4, 2, 3], [1, 0, 4, 2, 3], [1, 0, 4, 2, 3],
[1, 0, 4, 2, 3], [1, 0, 4, 2, 3], [1, 0, 4, 2, 3], [1, 0, 4, 2, 3], [1, 0, 4, 2, 3],
[1, 0, 4, 2, 3]]
But the example append out of the loop works properly:
['a', 'b', 'c']
I really can't see why the output it's like this, instead of append at the end, it just create a list with all the same value. But if i use append out of the loop it works.