def filter_4byte_chars(s):
    i = 0
j = len(s)
s = list(s)
while i < j:
    k = ord(s[i])
if k <= 127:
    i += 1
elif k < 224:
    i += 2
elif k < 240:
    i += 3
else:
    s[i:i + 4] = []
j -= 4
return ''.join(s)
How to filter (or replace) unicode characters that would take more than 3 bytes in UTF-8?