RosettaCodeData/Task/Determine-if-a-string-has-all-the-same-characters/Python/determine-if-a-string-has-all-the-same-characters-3.py

10 lines
303 B
Python
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
# 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()
)