mercredi 25 septembre 2019

if- else statement in one line code python; syntax error

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]

Aucun commentaire:

Enregistrer un commentaire