RosettaCodeData/Task/Determine-if-a-string-has-all-the-same-characters/Python/determine-if-a-string-has-all-the-same-characters-3.py
2023-07-01 13:44:08 -04:00

9 lines
303 B
Python

# inconsistentChar :: String -> Maybe (Int, Char)
def inconsistentChar(s):
'''Just the first inconsistent character and its index,
or Nothing if all the characters of s are the same.
'''
return next(
(Just(ix) for ix in enumerate(s) if s[0] != ix[1]),
Nothing()
)