I'm surprised that no one has talked about using ord in python (It Returns the Unicode code point for a string) and comparing the sum
ord
>>> sum(map(ord, 'stressed')) == sum(map(ord, 'desserts')) True
It even performs better than sorting
>>> timeit.timeit("sorted('stressed') == sorted('desserts')") 1.3272779149992857
>>> timeit.timeit("sum(map(ord, 'stressed')) == sum(map(ord, 'desserts'))") 1.2404647049988853
It performs better but it's wrong. Comparing sums can give you false positives.
>>> sum(map(ord, 'false positive')) 1438 >>> sum(map(ord, 'farce positivo')) 1438 >>>
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I'm surprised that no one has talked about using
ord
in python (It Returns the Unicode code point for a string) and comparing the sumIt even performs better than sorting
It performs better but it's wrong. Comparing sums can give you false positives.