P
P
pilityxxx2020-08-15 02:35:30
Python
pilityxxx, 2020-08-15 02:35:30

How to remove letters from a list, add numbers Python?

There is a list -

['R.99', 'R.990', 'R.1190', 'R.1990', 'R.1290', 'R.1390', 'R.1490', 'R.990' ', 'b.1590', 'b.1690', 'b.1790', 'b.1890']

You need to get the following list from it - ['99', '990', '1190', '1990', '1290', '1390', '1490', '990', '1590', '1690', '1790', '1890']

And then add all the numbers in the list and get the answer 13,389

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2020-08-15
@pilityxxx

Are the letters always the same? If yes, then . If not, you can use regular expressions: . sum(int(n[2:]) for n in arr)
sum(int(re.sub(r'\D', '', n)) for n in arr)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question