Poner en mayúscula la primera letra y las restantes en minúsculas
Definir la función
| 
					 1  | 
						   mayusculaInicial :: String -> String  | 
					
tal que mayusculaInicial xs es la palabra xs con la letra inicial en mayúscula y las restantes en minúsculas. Por ejemplo,
| 
					 1 2  | 
						   mayusculaInicial "sEviLLa"  ==  "Sevilla"    mayusculaInicial ""         ==  ""  | 
					
Soluciones
A continuación se muestran las soluciones en Haskell y las soluciones en Python.
| 
					 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53  | 
						import Data.Char (toUpper, toLower) import Test.QuickCheck -- 1ª solución -- =========== mayusculaInicial1 :: String -> String mayusculaInicial1 []     = [] mayusculaInicial1 (x:xs) = toUpper x : [toLower y | y <- xs] -- 2ª solución -- =========== mayusculaInicial2 :: String -> String mayusculaInicial2 [] = [] mayusculaInicial2 (x:xs) = toUpper x : aux xs   where aux (y:ys) = toLower y : aux ys         aux []     = [] -- 3ª solución -- =========== mayusculaInicial3 :: String -> String mayusculaInicial3 [] = [] mayusculaInicial3 (x:xs) = toUpper x : map toLower xs -- Comprobación de equivalencia -- ============================ -- La propiedad es prop_mayusculaInicial :: String -> Bool prop_mayusculaInicial xs =   all (== mayusculaInicial1 xs)       [mayusculaInicial2 xs,        mayusculaInicial3 xs] -- La comprobación es --    λ> quickCheck prop_mayusculaInicial --    +++ OK, passed 100 tests. -- Comparación de eficiencia -- ========================= -- La comparación es --    λ> length (mayusculaInicial1 (take (10^7) (cycle "aA"))) --    10000000 --    (2.22 secs, 1,680,592,240 bytes) --    λ> length (mayusculaInicial2 (take (10^7) (cycle "aA"))) --    10000000 --    (2.57 secs, 2,240,592,192 bytes) --    λ> length (mayusculaInicial3 (take (10^7) (cycle "aA"))) --    10000000 --    (0.16 secs, 1,440,592,192 bytes)  | 
					
| 
					 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73  | 
						from sys import setrecursionlimit from timeit import Timer, default_timer from hypothesis import given from hypothesis import strategies as st setrecursionlimit(10**6) # 1ª solución # =========== def mayusculaInicial1(xs: str) -> str:     if xs:         return "".join([xs[0].upper()] + [y.lower() for y in xs[1:]])     return "" # 2ª solución # =========== def mayusculaInicial2(xs: str) -> str:     def aux(ys: str) -> str:         if ys:             return ys[0].lower() + aux(ys[1:])         return ""     if xs:         return "".join(xs[0].upper() + aux(xs[1:]))     return "" # 3ª solución # =========== def mayusculaInicial3(xs: str) -> str:     if xs:         return "".join([xs[0].upper()] + list(map(str.lower, xs[1:])))     return "" # 4ª solución # =========== def mayusculaInicial4(xs: str) -> str:     return xs.capitalize() # Comprobación de equivalencia # ============================ # La propiedad es @given(st.text()) def test_mayusculaInicial(xs: str) -> None:     r = mayusculaInicial1(xs)     assert mayusculaInicial2(xs) == r     assert mayusculaInicial3(xs) == r # La comprobación es #    src> poetry run pytest -q mayuscula_inicial.py #    1 passed in 0.26s # Comparación de eficiencia # ========================= def tiempo(e: str) -> None:     """Tiempo (en segundos) de evaluar la expresión e."""     t = Timer(e, "", default_timer, globals()).timeit(1)     print(f"{t:0.2f} segundos") # La comparación es #    >>> tiempo('len(mayusculaInicial1("aB"*(10**7)))') #    1.92 segundos #    >>> tiempo('len(mayusculaInicial2("aB"*(10**7)))') #    Process Python terminado (killed) #    >>> tiempo('len(mayusculaInicial3("aB"*(10**7)))') #    1.59 segundos #    >>> tiempo('len(mayusculaInicial4("aB"*(10**7)))') #    0.13 segundos  |