How can I multiply dictionary values with value in string?

I need to multiply values of damages with values/list/ with value of conversion /dictionary/
That’s my task / Write a function that returns a new list of updated damages where the recorded data is converted to float values and the missing data is retained as "Damages not recorded"/

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’]

conversion = {“M”: 1000000,
“B”: 1000000000}
for damage in damages:

if damage[-1]== “M”:
stripped = damage[:2]
converting = conversion[“M”]
print(stripped * converting)

you need to change it to a float before multiplying
like
stripped = float(damage[:-1])

y = float('306') print(y) print(y * 10) print('\n') stripped = '1.01' y = float(stripped) print(y) print(y * 2)
1 Like

Thank you so much :grinning: :grinning: :grinning: