I have a dictionary and using .keys() to convert into a list of keys then lower case the keys and sort the list, like this:
dictionary = list()
# covert all to lower case
for word in self._dict.keys():
dictionary.append(word.lower())
dictionary.sort()
print dictionary[:5]
prints [u'a', u'a', u'aa', u'aa', u'aaa']
Why elements are duplicated?
UPDATE: stupid me, didn’t think of there might be lower case letters in the original dictionary… pure embarrassment
Because you’ve converted the keys to lower case. For example:
So, if you had a class defined like this:
And then an instance of it:
Converting the keys to lower case results in duplicates: