Python 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")


elif “B” in number:

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


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