0

Is removing certain elements from a list by random.choice possible in Python?

Say I had a program make a random choice and it selected the third element in the list. The third element would be removed from the list. In response, the fourth, fifth and sixth elements would also be removed from the list. How can I make that happen?

24th Nov 2019, 9:31 PM
Steven Iannucci
Steven Iannucci - avatar
1 Odpowiedź
+ 2
So you want to remove all elements after the chosen one (including the chosen one)? from random import randrange del your_list[randrange(len(yourlist)):]
25th Nov 2019, 12:34 AM
HonFu
HonFu - avatar