I have this problem where I want to remove a list element if it contains 'illegal' characters. The legal characters are specified in multiple lists. They are formed like this, where alpha stands for the alphabet (a-z + A-Z), digit stands for digits (0-9) and punct stands for punctuation (sort of).
alpha = list(string.ascii_letters)
digit = list(string.digits)
punct = list(string.punctuation)
This way I can specify something as an illegal character if it doesn't appear in one of these lists.
After that I have a list containing elements:
Input = ["Amuu2", "Q1BFt", "dUM€n", "o°8o1G", "mgF)`", "ZR°p", "Y9^^M", "W0PD7"]
I want to filter out the elements containing illegal characters. So this is the result I want to get (doesn't need to be ordered):
var = ["Amuu2", "Q1BFt", "mgF)`", "Y9^^M", "W0PD7"]
EDIT:
I have tried (and all variants of it):
for InItem in Input:
if any(AlItem in InItem for AlItem in alpha+digit+punct):
FilInput.append(InItem)
where a new list is created with only the filtered elements, but the problem here is that the elements get added when the contain at least one legal character. For example: "ZR°p" got added, because it contains a Z, R and a p.
I also tried:
for InItem in Input:
if not any(AlItem in InItem for AlItem in alpha+digit+punct):
but after that, I couldn't figure out how to remove the element. Oh, and a little tip, to make it extra difficult, it would be nice if it were a little bit fast because it needs to be done millions of times. But it needs to be working first.