("foo", "bar") < ("bar", "foo") < is true for second string ("bar", "foo") < ("foo", "bar") < is true for first string We fix this by fully comparing one string, then trying the other one.