Is it impossible to take out the tuples on the list?

Asked 2 years ago, Updated 2 years ago, 148 views

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

2022-09-20 15:32

1 Answers

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)]


2022-09-20 15:32

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.