Quote (jro1221 @ Sep 24 2015 07:01pm)
Code
elif itemType == "d":
itemType = "dresser"
itemOffer = input("Enter the maximum item cost:")
for itemOffer in range(0, len(myList)):
if myList[itemOffer] >= itemCost:
print "Sold", itemType, "for", itemCost
myList.remove([itemType, itemCost])
dList.remove([itemType, itemCost])
break
That is what I currently have, but I am running into 2 issues:
Lets say I have [[dresser, 15], [dresser, 17]] and I put in a value of 16 for item offer
It will print:
"Sold dresser for 17"
Then it will not delete anything.
When I want it to print:
"Sold dresser for 15"
Edit: Got it to delete now, but it is still finding and deleting the wrong item.
Code
>>> dressers = [[dresser, 15], [dresser, 17]]
>>> dressers.append([dresser, 16])
>>> sorted(dressers)
[[dressers , 15], [dressers , 16], [dressers , 17]]
>>> dressers.pop(2)
['', 16]
>>> dressers
[['', 15], ['', 17]]
pop would return the values from the index you need them from and also remove them in same action, which might be useful for what you need rather than manually calling remove.
I would honestly just use dictionaries, you could create
{key:value} objects quickly with lists formatted like these just using
dict(zip(list))This post was edited by j0ltk0la on Sep 25 2015 02:24am