Hi guys so just wondering how do I keep a word from a list to be deleted if it doesn't contain any alphabetical character but will not be deleted if it contains any alphabetical character followed by any kind of special character or number
say that I have a list of sentence/words which is the following:
['python','abc123','@@','!!','12345abc#','hello@','141351351','123abc']
the desired output will be:
['python','abc123','','','12345abc#','hello@','','123abc']
what i have tried is the following:
data = ['python','abc123','@@','!!','12345abc#','hello@','141351351','123abc']
regex = re.compile('[^a-zA-Z0-9&._-]')
filtered= [regex.sub('', each_data) for each_data in data ]
which result in this:
['python', 'abc123', '12345abc', 'hello', '141351351', '123abc']
which delete all the special character which is wrong i'm not sure how to fix this, I'm still thinking about how to solve it using regex, I had also tried with nltk and can't seem to find the answer either. Any kind of hint or help will be appreciated