Nov-09-2019, 12:33 AM
Of course, and not only I can understand but especially I can learn.
Your help to both was relevant and clear, thank you for your concern.
But in my answer (#3) I try to explain the reading of the code, when I read or write it, from a semantic point of view.
To make the difference, for example, between [tt for _ in range(4)] and [[0,1] for _ in range(4)] which gives different results.
I try to explain it as follows: in both cases we create a list of lists by iteration [... for _ in range(4)].
In the case with tt, the copied list is a variable that contains a list, which is why tt is not re-evaluated at each iteration, because it refers to the list that has been assigned to it and will give n copy with the same reference.
In the other ([0,1]) it is the literal expression of a list that contains two elements, this is the reason why [0,1] is re-evaluated at each iteration and which will give n independent copy therefore with different references.
In reading or writing the code the difference to be identified between [tt for _ in range(4)] and [[0,1] for _ in range(4)] is tt & [0,1], variable against literal form in list of lists creation by itération.
And of course we cannot identify this differences if we have not understood it and observed it.
Your help to both was relevant and clear, thank you for your concern.
But in my answer (#3) I try to explain the reading of the code, when I read or write it, from a semantic point of view.
To make the difference, for example, between [tt for _ in range(4)] and [[0,1] for _ in range(4)] which gives different results.
I try to explain it as follows: in both cases we create a list of lists by iteration [... for _ in range(4)].
In the case with tt, the copied list is a variable that contains a list, which is why tt is not re-evaluated at each iteration, because it refers to the list that has been assigned to it and will give n copy with the same reference.
In the other ([0,1]) it is the literal expression of a list that contains two elements, this is the reason why [0,1] is re-evaluated at each iteration and which will give n independent copy therefore with different references.
In reading or writing the code the difference to be identified between [tt for _ in range(4)] and [[0,1] for _ in range(4)] is tt & [0,1], variable against literal form in list of lists creation by itération.
And of course we cannot identify this differences if we have not understood it and observed it.