Skip to content

Instantly share code, notes, and snippets.

@holocronweaver
Forked from DreamPhage/replace_item
Created November 20, 2012 02:29
Show Gist options
  • Save holocronweaver/4115551 to your computer and use it in GitHub Desktop.
Save holocronweaver/4115551 to your computer and use it in GitHub Desktop.
Ben's replace_item function v2
#this function replaces an existing index with a new one.
def replace_item(inventory,new_item):
for i,item in enumerate(inventory):
if item != new_item:
inventory[i] = new_item
return inventory
my_inv = [0]*26
sword = "sword"
bow = "bow"
print replace_item(my_inv, sword)
print replace_item(my_inv, bow)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment