0

I have a dictionary which looks like this.

{ latex schlüpfer : [455, 'latex schl\xc3\xbcpfer', 5.0, 0.0, 0.0, 24.6] }

Why is my list value at index 1 showing in a different encoding?

I've tried replacing it with the key as well as appending it and it always comes out the same.

Even when I go:

print key # latex schlüpfer 
print [key] # latex schl\xc3\xbcpfer

What's going on?

I'm trying to check if the item exists but the encoding issues appear to be preventing me from doing this as I'm comparing latex schl\xc3\xbcpfer to latex schlüpfer

2 Answers 2

1

objects inside a list are printed using their __repr__ method. this reproduces your output:

# coding=utf-8
s = 'latex schlüpfer'
print(s)
print(repr(s))

it prints

latex schlüpfer
'latex schl\xc3\xbcpfer'
Sign up to request clarification or add additional context in comments.

3 Comments

Yes, ignore the words haha
So should comparing the values be right or will they also be their repr versions?
the comparison wil not use repr (repr is just a [short] string representation of an object; comparison calls these methods).
0

You can try to encode your entire dictionary by using the follow code:

mydict = {k: unicode(v).encode("utf-8") for k,v in mydict.iteritems()}

This uses a dictionary comprehension.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.