I have a list that looks like this:
name_list=['ramon del rio,georgina genes,jorge lópez']
And I want to create a byte array. To do this I am running the following code,
for i in name_list:
name_list_bytes.append(list(map(lambda x: str.encode(x, "UTF-8"), i.split(','))))
print(name_list_bytes)
[b'ramon del rio', b'georgina genes', b'jorge l\xf3pez']
As you can see the name "jorge lópez" is transformed "to "jorge l\xf3pez". How can I overpass this transformation and transform the name correctly?
[EDIT]
I found out that python encode function has a 2nd argument that controls the characters and what should python do when those characters are present in the string.
for i in name_list:
name_list_bytes.append(list(map(lambda x: str.encode(x, "ascii", "ignore"), i.split(','))))
print(name_list_bytes)
[b'ramon del rio', b'georgina genes', b'jorge lpez'] #removes the unknown asscii character.
The "ignore" arguments removes the ascii characters, although I am looking for replacing them with the proper value. I guess that the best way although tedious is to identify those characters and replace them by hand.