Determine if a string has all unique characters: Difference between revisions

Content added Content deleted
(→‎Python :: Functional: Added a variant in terms of sorting and grouping)
Line 883: Line 883:
if duplications:
if duplications:
dup = sorted(duplications, key=lambda kv: kv[1][0])[0]
dup = sorted(duplications, key=lambda kv: kv[1][0])[0]
return Just(([x[0] for x in dup[1]], dup[0]))
return Just((dup[0], [x[0] for x in dup[1]]))
else:
else:
return Nothing()
return Nothing()
Line 899: Line 899:
return repr(s) + ' (' + str(len(s)) + ')'
return repr(s) + ' (' + str(len(s)) + ')'


def showDuplicate(ixc):
def showDuplicate(cix):
ix, c = ixc
c, ix = cix
return repr(c) + (
return repr(c) + (
' (' + hex(ord(c)) + ') at ' + repr(ix)
' (' + hex(ord(c)) + ') at ' + repr(ix)