VaultBy ENSAMIENParrainage
PY13 lines

ex2-positions.py

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
"""TP5 ex2 : positions de chaque caractère d'une chaîne."""

def indice(chaine):
    d = {}
    for index, char in enumerate(chaine, start=1):
        if char in d:
            d[char].append(index)
        else:
            d[char] = [index]
    return d
chaine = "Mohammed"
resultat = indice(chaine)
print(resultat)

    Type at least 2 letters. ↑ ↓ to move, Enter to open.