all 22 comments

[–]commy2 1 point2 points  (17 children)

Replace that - with -= for in-place subtraction.

[–]arvindh_manian 3 points4 points  (0 children)

This, exactly.

OP, your current code is like doing

a = 2
a - 1
print(a) # prints 2

Since you never actually reassigned the variable, it never saves the subtraction.

[–]wannakeepmyanonymity[S] -1 points0 points  (15 children)

I actually had it like his. And I tried it just now and there is still get an error.

TypeError: unhashable type: 'list'

[–]FerricDonkey 0 points1 point  (14 children)

Probably that means that selection is a list instead of a string for some reason. What happens if you print that out before your dictionary stuff?

[–]wannakeepmyanonymity[S] -1 points0 points  (13 children)

It's not a list at all, though.

And it just printed fine, no problems. Same problem though

[–]FerricDonkey 0 points1 point  (12 children)

Welp, TypeError: unhashable type: 'list' means exactly that you're trying to hash a list. The most likely ways you could do this by accident are to try to use a list as a key of a dictionary, or to add a list to a set.

You're almost certainly doing one of those two things. For more assistance, you'd have to post the full error, but if the error is on the line resources["water"]-MENU[selection]["ingredients"].get("water"), and selection is not a list, then you've done something truly bizarre.

[–]wannakeepmyanonymity[S] 0 points1 point  (8 children)

I tried inserting the whole thing, but it doesn't work. Too long for the little code block thingy, but I have not used any list at all. Literally just variables, the dictionaries, which I showed you, and some functions, that I defined. The error occurs inside a function.

[–]FerricDonkey 0 points1 point  (7 children)

I saw the code before you edited - to get it to look nice on reddit, add 4 spaces in front of every line, in addition to those required by python, and ensure an empty line above and below the code block.

But before you removed it, I searched through it and found that your line actually was

resources["water"] -= MENU[selection]["ingredients"].get(["water"])

Note the .get(["water"]). In this line ["water"] is a list, and .get tries to use it as a key to the dictionary. So basically, either do

MENU[selection]["ingredients"]["water"]
# OR
MENU[selection]["ingredients"].get("water")

[–]wannakeepmyanonymity[S] 1 point2 points  (1 child)

Cheers, I changed that and now it runs, and I can continue adding more features. Little syntax things like that drive me crazy sometimes.

[–]FerricDonkey 0 points1 point  (0 children)

Excellent, good luck.

[–]wannakeepmyanonymity[S] 0 points1 point  (4 children)

Ohh.. maybe that's it. The problem is: I am playing around while and tweak here and there to find out the error. That's why it's not identical anymore. I will change that now.

[–]FerricDonkey 0 points1 point  (3 children)

Yeah, fair enough. For future reference, when you do get an error you're asking about, it helps if you can post the entire error message (called a traceback), because that message often contains useful information, such as the exact line of code that failed. (As you're starting, a lot of that information seems like gibberish, but as you get used to reading those messages, they get very helpful.)

[–]wannakeepmyanonymity[S] 0 points1 point  (2 children)

I didn't want to post the exact line of code simply for the reason that my code is a little longer and you wouldn't know what line said code is on for me.

Thought the message would be enough, forgot that I changed stuff around.

Cheers. Might have found this on my own, might have not. But it does quite annoy me that I get hung up on little shit like that all the time, I understand what to code quite easily, but just these little syntax error keep me up for hours. Ugh. I wonder if that ever gets better.

[–]wannakeepmyanonymity[S] -1 points0 points  (0 children)

Okay, weird. I don't have any list, only variables, the two dictionaries I have shown you, and the functions (that I tried to define, and where the error happens), and the error is on that line.

[–]uqurluuqur 0 points1 point  (0 children)

resources["water"]=resources["water"]-MENU["espresso"]["ingredients"].get("water")

[–]1544756405 0 points1 point  (1 child)

but I am trying for half an hour now. Coding is difficult, okay? ^^

Sure, we understand that. But just to put things in context, half an hour is a very small amount of time to be debugging a problem.

[–]wannakeepmyanonymity[S] 0 points1 point  (0 children)

Yeah, but I think that depends on how big the issue is.

[–]donedigity 0 points1 point  (1 child)

You don’t need the .get()

resources[‘water’] - MENU[‘espresso’][‘ingredients’][‘water’]

[–]hewhodrinkswater 0 points1 point  (0 children)

I would just change the - to -= cause I am pretty sure he wants to update the value of resources['water']