Python | Remove random element from list
Sometimes, while working with Python lists, we can have a problem or part of it, in which we desire to convert a list after deletion of some random element. This can have it’s application in gaming domain or personal projects. Let’s discuss certain way in which this task can be done.
Method : Using
randrange() + pop()
In this, we just combine the functionality of above functions into one and achieve this task. The random element is chosen by
randrange() and then is accessed and removed from the list using
The original list : [6, 4, 8, 9, 10] List after removal of random number : [6, 4, 8, 10]