[Python] Filter out numbers from text using list comprehension

Discussão em 'Python' iniciado por Stack, Maio 2, 2025.

  1. Stack

    Stack Membro Participativo

    I have a small text with currency values. I would like to save only the values without the currency signs in a list. Here is my working example so far

    Text = "Out of an estimated $5 million budget, $3 million is channeled to program XX, $1 million to program YY and the remainder to program ZZ"

    amount = [x for x in Text.split() if x.startswith('$')]


    Current code saves the values (with currency sign). How do i strip the values of the dollar sign?

    Continue reading...

Compartilhe esta Página