>>> from ast import literal_eval
>>> H = {"('a','b')":1}
>>> x = ('a','b')
>>> str(x)
"('a', 'b')"
>>> list(H.keys())[0]
"('a','b')"
>>> str(x) == list(H.keys())[0]
False
Why do I get a False statement? However, when I do
>>> x == literal_eval(list(H.keys())[0])
True
I get a True statement.
>Solution :
In my tests, str(x) is "('a', 'b')". Do you notice the space after the comma?
That is enough to explain why the strings are different (one contains a space while the other does not), while the tuples are equal.