I am trying to pass some strings in my function and remove some specific letters. I am able to do so with the function I have written below.
def str_to_list( str ) :
remove_characters = ["e", "s"]
for character in remove_characters :
li = list(str.replace(character, ""))
return li
in: 'my string'
out: m,y, ,t,r,i,n,g
But it maybe so that some strings that are passed could contain some integers as well and I want to remove them with condition. Those integers could be condition based. But the strings are always given. So I need to automate for integers only. For example remove integers from my string if they are greater than 1 as shown below. It should be like this:
in: '1direction'
out: 1,d,i,r,c,t,i,o,n
in: 2cent
out: c,n,t
I want to use list for this purpose and do not want to use ASCII for integers. Is it possible somehow to pass those integers as a condition in my remove_characters. It would be great if it could be achieved here rather than writing a new code altogether.
Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire