I need to make a list from a string and I need to remove the numbers and/or punctiations before adding them to the list. I have written something but it adds only number words as " " spaces. So I have added an "elif" statement to pass all number words but somehow I am uneasy. I can't use regex so is there another aproach or how can I improve this code? Appriciate for help. Here is my codes:
my_text = " This3 is a sentence6 that1 I have written 44 to see 5 if this code works so that it makes a list of words from using this code"
new_text = my_text.split()
cleared_text = []
for word in new_text:
if word.isalpha():
cleared_text.append(word)
elif word.isnumeric():
pass
else:
containeer = ""
for letter in word:
if letter.isalpha():
containeer += letter
cleared_text.append(containeer)
print(cleared_text)
My main target is to store words from the string in a dictionary then show how many times a word repeated so is it better to do do this task from list to dictionary instead of list to list then to dictionary.
Thank you all, my regards