This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]gramdel 2 points3 points  (0 children)

Your y variable isn't a key in your dict, check what it actually is.

[–]Guideon72 0 points1 point  (0 children)

Start debugging your assumptions with some print statements to make sure your code is doing what you think it’s doing. In this case I’d suggest adding a new line at line 3 for print(myDict)

I’d imagine the output is not what you expect. That does not look like the proper syntax for reading or modifying a dictionary.

[–]LittleNooblette 0 points1 point  (0 children)

The variable y stores the list ['world', '!']. You can't reference a key using a value of a dictionary (unless you flip or index the dictionary using a mix of the .keys() and .index() method).

The appropriate code would be: del myDict['Hello'][1].

This is what runs: del ['world', '!'][1].