NO NUMERALS how to make it cleaner or more elegant | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

NO NUMERALS how to make it cleaner or more elegant

letters = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"] sentence = input() def transform(phrase): for x in range(11): if str(x) in phrase: pos = phrase.index((str(x))) phrase[pos] = letters[x] return phrase def manip(item): new_list = transform(item.split()) return ' '.join(new_list) print(manip(sentence))

27th Dec 2019, 4:09 PM
Maui
Maui - avatar
2 Answers
+ 5
I think, manip doesn't do enough to be a function of its own. Just convert the string to a list directly in transform, then return ' '.join(phrase).
27th Dec 2019, 4:54 PM
HonFu
HonFu - avatar
+ 2
Thanks for the feedback!
27th Dec 2019, 6:16 PM
Maui
Maui - avatar