how to check if there is content in multiple indexes of a list in one statement (python) -
I am creating a list consistent system for a text based RPG. The actual list is a list with 5 lists. For example, every item in my game can only go to specific slots of the inventory, for example, a sword can go into the first slot (rams only weapon) and two different slots.
If the player decides to pick one item in the game and it is a sword, here is the code:
inventory = [none] * 5 def PKwapite (Self): If self.Lot == 1: If the list is not [0]: list [0] = self.Name
So I have seen that the sword slot is empty and Is available, but if it is not, then I have to check whether the index 3 or 4 is empty and available or not. So, if possible, I want to set the sword in the available index (put items in empty slots).
Is it possible to do this?
Thank you!
You can use list estimation to create a list of available indices and then Select where the item can go. Here's an example:
inventory_test.py
inventory = ['full', none, 'full', none, someone No] melee_indices = (0, 3, 4) def add_item (name): Indices = [if the list [i] is not for i in ilee_indices] if lane (index)> gt; 0: list [index [0]] = name return true return incorrect print repr (inventory) add_item ('sword') print repr (inventory)
Result:
['complete', none, 'complete', none, none] ['full', none, 'full', 'sword', none]< / Div>