0

I just want to convert the number in text and if it is a text just return the word, but I get a syntax error after else. Is it possible to write the statement in one line?

text = [p.number_to_words(words) for words in text if words.isdigit() else words]
1
  • 1
    In the future when asking questions about errors, always please copy-paste the errors into the question, in full and complete, and as text. Commented Sep 25, 2019 at 10:20

1 Answer 1

3

Just move the if ... else before the for ... in:

text = [p.number_to_words(words) if words.isdigit() else words for words in text]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.