mardi 1 octobre 2019

Exclude value from an array in python

I have a list of values, selected 4 of them randomly and now want to exclude those four random values from the main list. How can I do that in Python?

                     Main_list=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
                     random_list = random.sample(xrange(10), 4)
                     selected_values = [0,0,0,0];
                     for i in range(0, len(random_list)):
                             selected_values[i] = Main_list[random_list[i]]
                     print 'selected values:', selected_values

results would be like: selected values: [2, 5, 9, 3]

so now how to exclude the randomly selected value from the main list?

Thank you, Kaze




Aucun commentaire:

Enregistrer un commentaire