can someone please tell me why is my list not empty?
#Function that verify if a word is a latin word (delivers true) or not (delivers false)
# -*- coding: utf-8 -*-
def is_latin(word):
try:
word.encode(encoding='utf-8').decode('ascii')
except UnicodeDecodeError :
print(word) # for debugging purposes
return False
else:
return True
# Function to eliminate a latin word from a given List of Strings
def eliminate_non_latin(initial_list):
for element in initial_list:
if not is_latin(element):
initial_list.remove(element)
return initial_list
#Testing the two functions
Test=['幸福','المغرب']
print(eliminate_non_latin(Test))
Output:
- 幸福 ====> is_latin function works fine (Debugging)
- ['المغرب'] ====> here's my problem this list should be empty!
Am i missing something?