Given the following code:
from itertools import combinations
l_a = [1,2,3]
l_b = ["a","b","c"]
l_c = [0.1,0.2,0.3]
l_abc = [l_a,l_b,l_c]
l_com = combinations(l_abc,2)
print("l_abc t1 : ",l_abc) #t1
print("l_com t1 : ",*l_com) #t1
print("--------------")
l_a.append(4)
print("l_abc t2 : ",l_abc) #t2
print("l_com t2 : ",*l_com) #t2
The output is:
l_abc t1 : [[1, 2, 3], ['a', 'b', 'c'], [0.1, 0.2, 0.3]]
l_com t1 : ([1, 2, 3], ['a', 'b', 'c']) ([1, 2, 3], [0.1, 0.2, 0.3]) (['a', 'b', 'c'], [0.1, 0.2, 0.3])
--------------
l_abc t2 : [[1, 2, 3, 4], ['a', 'b', 'c'], [0.1, 0.2, 0.3]]
l_com t2 :
After the construction of a list of 3 lists (l_abc):
- t1: When I print the result of itertools.combinations (l_com) in time 1 (t1), it gives the correct results.
- t2: I modify one list (l_a) that is part of the whole list of 3 lists (l_abc). When I print again the result of the previous combinations, the results is empty.
However, you can see that, for printing only list of lists (l_abc) work fin in t1 and after the updating in t2.
Q1) Why is that, and
Q2) How I can get the correct combinations in t2 ? (naivly call again the combinations second time).
Thanks.