mardi 22 octobre 2019

How to remove duplicate values generated randomly from list in python

I am having a list of input points as:

input_points = [{'name': 'a', 'value': (0.0, 1.0)}, {'name': 'b', 'value': (2.0, 1.0)},
                {'name': 'c', 'value': (3.0, 1.0)}, {'name': 'd', 'value': (0.0, 3.0)},
                {'name': 'e', 'value': (1.0, 2.0)}, {'name': 'f', 'value': (1.5, 1.5)},
                {'name': 'g', 'value': (1.0, 1.0)}, {'name': 'h', 'value': (1.5, 2.0)}]

I have to generate two random points iteratively. I am using random.sample() as:

for x in range(100):
    point1 = random.sample(input_points, 2)
    print(point1)

But it gives me a combination of duplicate points that's why I am not getting the combination of all the points from the list in 100 iterations all the time. But I have to traverse all the points in 100 iterations only. Is there any way I can remove the duplicates do that I get the combination of all the points in 100 iterations.

Thanks




Aucun commentaire:

Enregistrer un commentaire