Consider below example:
random_tile = random.choice(tiles)
del random_tile
It first assigns a random element from the list tiles to a variable, and then calls a function on that variable.
Then if we want to shorten the code as follows:
del random.choice(tiles)
We would get a SyntaxError: can't delete function call. I tried eval() with no luck. How can this be solved?
EDIT:
What I am trying to do is to remove a element from the tiles list at random. I thought I found a more compact way of doing it other than using random.randint() as the index, but I guess not.
Is there a pythonic/conventional way of doing this otherwise?
delis not a function, it is a keyword to create del statements e.g.del var. You can’t use it as a function or on a function, it can only be applied to a variable name, list of variable names or subscriptions and slicings e.g.To remove the random item you can try this
BUT it is not best way to remove items because it could mean a internal search for items and item comparison, also won’t work if items are not unique, so best would be to get random index and delete that