Trying to get the key from a dictionary reference. I'm basically looping over a list which is essentially a path to get down into a dictionary. If a key doesn't exist I'm creating it, but I need to do something based on the name of the previous key. Is there a way to get that info or should I just store it as another variable and constantly overwrite it?
Here's my code:
for obj in noun_adj: # loop noun/adj
if obj:
try:
work_on = work_on[obj] # Store it as a reference to work on
except KeyError: # If there isn't a key stored yet
# I need the current key of work_on here...