fox fox - 1 month ago 9
Python Question

python: a quick way to return list without a specific element

If I have a list of card suits in arbitrary order like so:

suits = ["h", "c", "d", "s"]


and I want to return a list without the
'c'


noclubs = ["h", "d", "s"]


is there a simple way to do this?

Answer
>>> suits = ["h","c", "d", "s"]
>>> noclubs = list(suits)
>>> noclubs.remove("c")
>>> noclubs
['h', 'd', 's']

If you don't need a seperate noclubs

>>> suits = ["h","c", "d", "s"]
>>> suits.remove("c")