-2

Here is my code if that helps you answer the question

import random

Exlist = ['pl1', 'pl2']
Exvar = random.choice(Exlist)
print(Exvar)
Exlist = Exlist - list(Exvar)

I tried changing Exvar to a list

  • I recommend that you check [the documentation](https://docs.python.org/3/tutorial/datastructures.html) to see all of the functions you can do with lists. Scan down the page to see if any of these functions look like they will do what you want. – Code-Apprentice Feb 03 '23 at 17:11
  • 1
    Does this answer your question? [Is there a simple way to delete a list element by value?](https://stackoverflow.com/questions/2793324/is-there-a-simple-way-to-delete-a-list-element-by-value) – Code-Apprentice Feb 03 '23 at 17:11

3 Answers3

1

Use remove(). For example,

import random

Exlist = ['pl1', 'pl2']
Exvar = random.choice(Exlist)
print(Exvar)
Exlist.remove(Exvar)
meable
  • 118
  • 8
0

In order to remove something from a list you can either remove() or pop() or possibly reconstruct the list omitting the element that's not required

DarkKnight
  • 19,739
  • 3
  • 6
  • 22
0

You can use remove() to remove item by content example:

Exlist.remove(Exvar)

You can use pop() to remove the last item or pass the index as parameter to remove specific item example:

Exlist.pop()
Exlist.pop(index)

You can also use del keyword to remove item by index example:

del Exlist[index]