Я пытаюсь удалить все элементы из списка, которые содержат определенный символ, а именно "z", "l" или "t". Вот что у меня есть:
def run():
words = ['the', 'of', 'and', 'to', 'a', 'in', 'for', 'is', 'on', 'that', 'by', 'this', 'with', 'i', 'you', 'it', 'not', 'or', 'be', 'are', 'from', 'at', 'as', 'your', 'all', 'have', 'new', 'more', 'an', 'was', 'we', 'will', 'home', 'can', 'us', 'about', 'if', 'page', 'my', 'has', 'search', 'free', 'but', 'our', 'one', 'other', 'do', 'no', 'information', 'time', 'they', 'site', 'he', 'up', 'may', 'what', 'which', 'their', 'news', 'out', 'use', 'any', 'there', 'see', 'only', 'so', 'his', 'when', 'contact', 'here', 'business', 'who', 'web', 'also', 'now', 'help', 'get', 'pm', 'view', 'online', 'c', 'e', 'first', 'am', 'been', 'would', 'how', 'were', 'me', 's', 'services', 'some', 'these', 'click', 'its', 'like', 'service', 'x', 'than', 'find', 'price', 'date', 'back', 'top', 'people', 'had', 'list', 'name', 'just', 'over', 'state', 'year', 'day', 'into', 'email', 'two', 'health', 'n', 'world', 're', 'next', 'used', 'go', 'b', 'work', 'last', 'most', 'products', 'music', 'buy', 'data', 'make', 'them', 'should', 'product', 'system', 'post', 'her', 'city', 't', 'add', 'policy', 'number', 'such', 'please', 'available', 'copyright', 'support', 'message', 'after', 'best', 'software', 'then', 'jan', 'good', 'video', 'well', 'd', 'where', 'info', 'rights', 'public', 'books', 'high', 'school', 'through', 'm', 'each', 'links', 'she', 'review', 'years', 'order', 'very', 'privacy', 'book', 'items', 'company', 'r', 'read', 'group', 'sex', 'need', 'many', 'user', 'said', 'de', 'does', 'set', 'under', 'general', 'research', 'university', 'january', 'mail', 'full', 'map', 'reviews', 'program', 'life', 'know', 'games', 'way', 'days', 'management', 'p', 'part', 'could', 'great', 'united', 'hotel', 'real', 'f', 'item', 'international', 'center', 'ebay', 'must', 'store', 'travel', 'comments', 'made', 'development', 'report', 'off', 'member', 'details', 'line', 'terms', 'before', 'hotels', 'did', 'send', 'right', 'type', 'because', 'local', 'those', 'using', 'results', 'office', 'education', 'national', 'car', 'design', 'take', 'posted', 'internet', 'address', 'community']
f = ['z', 'l', 't']
finished = False
while finished == False:
rep = False
while rep == False:
for x in range(len(words)):
for filterWord in f:
try:
if filterWord in words[x]:
words.pop(x)
break
except Exception as e:
rep = True
finished = True
print(words)
print(len(words))
Я ожидаю, что выходные данные этой функции вернут все слова, которые не содержат ['z', 'l', 't'], как это:
['of', 'and', 'a', 'in', 'for', 'is', 'on', 'by', 'i', 'you', 'or', 'be', 'are', 'from', 'as', 'your', 'have', 'new', 'more', 'an', 'was', 'we', 'home', 'can', 'us', 'if', 'page', 'my', 'has', 'search', 'free', 'our', 'one', 'do', 'no', 'he', 'up', 'may', 'which', 'news', 'use', 'any', 'see', 'so', 'his', 'when', 'here', 'business', 'who', 'web', 'now', 'pm', 'view', 'c', 'e', 'am', 'been', 'how', 'were', 'me', 's', 'services', 'some', 'service', 'x', 'find', 'price', 'back', 'had', 'name', 'over', 'year', 'day', 'n', 're', 'used', 'go', 'b', 'work', 'music', 'buy', 'make', 'her', 'add', 'number', 'such', 'message', 'jan', 'good', 'video', 'd', 'where', 'info', 'books', 'high', 'm', 'each', 'she', 'review', 'years', 'order', 'very', 'privacy', 'book', 'company', 'r', 'read', 'group', 'sex', 'need', 'many', 'user', 'said', 'de', 'does', 'under', 'research', 'january', 'map', 'reviews', 'program', 'know', 'games', 'way', 'days', 'p', 'f', 'ebay', 'made', 'off', 'member', 'before', 'did', 'send', 'because', 'using', 'office', 'car', 'design', 'address']
, но фактический вывод:
['of', 'and', 'a', 'in', 'for', 'is', 'on', 'by', 'i', 'you', 'or', 'be', 'are', 'from', 'as', 'your', 'have', 'new', 'more', 'an', 'was', 'we', 'home', 'can', 'us', 'if', 'page', 'my', 'has', 'search', 'free', 'our', 'one', 'do', 'no', 'he', 'up', 'may', 'which', 'news', 'use', 'any', 'see', 'so', 'his', 'when', 'here', 'business', 'who', 'web', 'now', 'pm', 'view', 'c', 'e', 'am', 'been', 'how', 'were', 'me', 's', 'services', 'some', 'service', 'x', 'find', 'price', 'back','had', 'name', 'over', 'year', 'day', 'n', 're', 'used', 'go', 'b', 'work','music', 'buy', 'make', 'her','add', 'number', 'such', 'message', 'jan', 'good', 'video', 'd', 'where', 'info', 'books', 'high', 'm', 'each', 'she', 'review', 'years', 'order', 'very', 'privacy', 'book', 'company', 'r', 'read', 'group', 'sex', 'need', 'many', 'user', 'said', 'de', 'does', 'under', 'research', 'january', 'map', 'reviews', 'program', 'know', 'games', 'way', 'days', 'p', 'f', 'ebay', 'comments', 'made', 'off', 'member', 'before', 'did', 'send', 'because', 'using', 'office', 'car', 'design', 'address']['of', 'and', 'a', 'in', 'for', 'is', 'on', 'by', 'with', 'i', 'you', 'not', 'or', 'be', 'are', 'from', 'as', 'your', 'have', 'new', 'more', 'an', 'was', 'we', 'home', 'can', 'us', 'if', 'page', 'my', 'has', 'search', 'free', 'our', 'one', 'do', 'no', 'time', 'site', 'he', 'up', 'may', 'which', 'news', 'use', 'any', 'see', 'so', 'his', 'when', 'here', 'business', 'who', 'web', 'now', 'get', 'pm', 'view', 'c', 'e', 'am', 'been', 'how', 'were', 'me', 's', 'services', 'some', 'click', 'like', 'service', 'x', 'find', 'price', 'back', 'people', 'had', 'name', 'over', 'year', 'day', 'email', 'health', 'n', 're', 'used', 'go', 'b', 'work', 'most', 'music', 'buy', 'make', 'should', 'system', 'her', 't', 'add', 'number', 'such', 'available', 'support', 'message', 'best', 'then', 'jan', 'good', 'video', 'd', 'where', 'info', 'public', 'books', 'high', 'through', 'm', 'each', 'she', 'review', 'years', 'order', 'very', 'privacy', 'book', 'company', 'r', 'read', 'group', 'sex', 'need', 'many', 'user', 'said', 'de', 'does', 'under', 'research', 'january', 'full', 'map', 'reviews', 'program', 'know', 'games', 'way', 'days', 'p', 'could', 'united', 'real', 'f', 'international', 'ebay', 'store', 'comments', 'made', 'report', 'off', 'member', 'line', 'before', 'did', 'send', 'type', 'because', 'those', 'using', 'office', 'national', 'car', 'design', 'posted', 'address']
Также, если функция не находит какой-либо элемент с запрещенным символом, она застревает в цикле while.
Спасибо за помощь. : 0)