Why won't this print?

why won’t this print?

I don’t think this line new_item = conversion[item[-1]] * item[:-1] will work the way you expect. You have a dict you’re using to convert part of your string, but what about the other part?

Thank you getting back to me. I will change the code regarding new_item and try a different approach. Which other part were you referring to exactly?

Sorry if that wasn’t clear, I meant that you start with a string and you use part of it to reference a dictionary which returns an integer but what about the other part of the string.

Hi there. I am working on the same project. This is one I feel all but completely lost on. Most of Codecademy is like that for me now.
Here is some code I cannot get to run. I practically copied it from others because the project is much like hopping on a motorcycle from the womb. Any thoughts as to why it returns a KeyError?

hurricanes = {}
def hurricane_dict(names, months, years, max_sustained_winds, areas_affected, update_damages, deaths):
  for i in range(len(names)):
    hurricanes[names[i]]: {"Name": names[i],
 "Month": months[i],
 "Year": years[i],
 "Max Sustained Wind": max_sustained_winds[i],
 "Areas Affected": areas_affected[i],
 "Damage": update_damages[i],
 "Deaths": deaths[i]}
  return hurricanes
# create hurricanes dictionary
print(hurricane_dict(names, months, years, max_sustained_winds, areas_affected, update_damages, deaths))

Thanks for your time.

1 Like

I’d encourage you take your time and maybe even revisit previous topics if you’ve wound up in a spot where each lesson becomes more confusing. Even if you’re only missing small bits of knowledge from earlier lessons, the gaps in knowledge only get wider when you start relying on solutions.

A key error suggests that you’ve attempted to use a key which doesn’t exist within a dictionary. Perhaps you could do a little debugging and use print to check what is in your hurricanes dictionary. Does your function actually work as expected?

The function runs. There is nothing in the dictionary.

It’s ok. I am not going back. I know there was no functional relationship from that exercise to the lessons. It is a noticeable theme. Obviously the best thing I can do is find better lessons elsewhere and probably try applying notebooks to my actual field of interest instead of building dictionary challenges.

1 Like

Sounds like it’s not working as expected. When updating an existing dictionary how would you add a new key and assign a value to it outside your function?

I feel the same way. There tends to be some major gaps in curriculum. I’m pretty lost on where to go in this project. I’m heavily relying on solutions. Really kind of took a leap in difficulty with this project.


I’m not sure exactly what the issue with using this strategy is. Would you be able to elaborate more specifically on what the issue might be? I used the code below and i can’t find any issue with it.

def damage_converter(damage_list):
  updated_list = []
  for entry in damage_list:
    if entry == "Damages not recorded":
  return updated_list

damages = damage_converter(damages)

does this create an output with an issue I’m not aware of?