expenses =['Grocery-200.00', 'Gas-100.78', \
'Rent-1200.00', 'Water-23.34', \
'Vacation-356.89', 'Phone-123.00']
Asked
Active
Viewed 60 times
-2

Chris
- 15,819
- 3
- 24
- 37
1 Answers
0
Just split on the "-", cast to float and sum:
sum([float(x.split("-")[1]) for x in expenses])

mmdanziger
- 4,466
- 2
- 31
- 47
-
You can pass a generator expression rather than a list comprehension in a case like this. :) – Chris Oct 03 '22 at 19:23