Python Hurricane Analysis

https://www.codecademy.com/paths/data-science/tracks/dscp-python-fundamentals/modules/dscp-python-dictionaries-challenge-projects/projects/hurricane-analysis

Hi all.

I don’t understand why this for loop isn’t replacing anything. I have this list above:
damages = [‘Damages not recorded’, ‘100M’, ‘Damages not recorded’, ‘40M’, ‘27.9M’, ‘5M’, ‘Damages not recorded’, ‘306M’, ‘2M’, ‘65.8M’, ‘326M’, ‘60.3M’, ‘208M’, ‘1.42B’, ‘25.4M’, ‘Damages not recorded’, ‘1.54B’, ‘1.24B’, ‘7.1B’, ‘10B’, ‘26.5B’, ‘6.2B’, ‘5.37B’, ‘23.3B’, ‘1.01B’, ‘125B’, ‘12B’, ‘29.4B’, ‘1.76B’, ‘720M’, ‘15.1B’, ‘64.8B’, ‘91.6B’, ‘25.1B’]

And this loop below:

for number in damages:

if “M” in number:

number.replace("M", "000000")

print(number)

elif “B” in number:

number.replace("B", "000000000")

print(number)

I know I have to do another “else” bit at the bottom for returning the no data hurricanes, but I can’t figure out for the life of me why my replacements aren’t doing anything. Help please!

p.s. I also tried making the numbers floats, because they’re strings to begin with, and it didn’t like that. As it is written above, I can get it to return, but with M’s and B’s, but with the float operation going I got an error.

for number in damages: will give you copies of the values in the list. Any changes made to these values are not persisted in the list. To update an element in the list we need to do the following

the_list[index] = "new value"
1 Like

This is what I did & it worked

onversion = {“M”: 1000000,
“B”: 1000000000}

def damage_converter(damage):
damage_converted =
temp_unit = “”
for unit in damage:
if ‘M’ in unit:
temp_unit = float(unit.replace(“M”, “”))
temp_unit *= conversion[“M”]
damage_converted.append(temp_unit)
elif ‘B’ in unit:
temp_unit = float(unit.replace(“B”, “”))
temp_unit *= conversion[“B”]
damage_converted.append(temp_unit)
else:
damage_converted.append(unit)
return damage_converted

print(damage_converter(damages))

typo this is

onversion = {“M”: 1000000,
“B”: 1000000000}

conversion = {“M”: 1000000,
“B”: 1000000000}