Problem with append list in loop - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Problem with append list in loop (/thread-24493.html) |
Problem with append list in loop - michaelko03 - Feb-16-2020 Here is my code import math import numpy as np z = 0 y= [] x = [] while z < 5: z = z + 1 t = 0 x.append([y]) while t < 8: A = 10 + t y.append(A) t = t + z print (x) I want to separate the result of y list in each cycle from the second while loop I expect the result will be [10,11,12,13,14,15,16,17], [10,12,14,16],[10,13,16], [10,14], [10,15] [10,16] but the outcome is [10,11,12,13,14,15,16,17,10,12,14,16,10,13,16,10,14,10,15,10,16 [10,11,12,13,14,15,16,17,10,12,14,16,10,13,16,10,14,10,15,10,16], [10,11,12,13,14,15,16,17,10,12,14,16,10,13,16,10,14,10,15,10,16], [10,11,12,13,14,15,16,17,10,12,14,16,10,13,16,10,14,10,15,10,16], [10,11,12,13,14,15,16,17,10,12,14,16,10,13,16,10,14,10,15,10,16]can anyone help me? Thank you |