I have a problem wrapping my head around trying to convert strings into lists and producing the desired output. So far I have this code:
def func():
characters = '?/><,.:;"[]{}=+()*&^%$#@!' # keeping ' and -
new_lst = []
user = input("String: ")
for i in user:
if (i not in characters):
#new_lst = user.split(' ')
new_lst += i # I know this is the problem but I just don't know where to go from here
print(new_lst)
For example:
Keep. hyphen- and apostrophe's only.
Current output:
'K', 'e', 'e', 'p', ' ', 'h', 'y', 'p', 'h', 'e', 'n', '-', ' ', 'a', 'n', 'd', ' ', 'a', 'p', 'o', 's', 't', 'r', 'o', 'p', 'h', 'e', "'", 's', ' ', 'o', 'n', 'l', 'y']
Desired output:
['Keep', 'hyphen-', 'and', "apostrophe's", 'only']
Thanks for any help!