import itertools
import random
n = [1,2,3]
a=list(itertools.combinations(n,2))
b=list(random.choice(a))
c =[]
for x in a:
if x not in b:
c.append(x)
print(a)
print(b)
print(c)
I want to put the value of element a minus element b in the C list, but it doesn't come out. Is there a way?
list tuple python
import itertools
import random
n = [1,2,3]
a=list(list(itertools.combinations(n,2)))
b=random.choice(a)
c =[]
for x in a:
if b != x:
c.append(x)
print(a)
print(b)
print(c)
[(1, 2), (1, 3), (2, 3)]
(2, 3)
[(1, 2), (1, 3)]
© 2024 OneMinuteCode. All rights reserved.