Last active
November 4, 2017 17:42
-
-
Save johannchopin/82d1a2c652026600f806cb2b79e155eb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LOWER_CASE_TO_CAPITAL = ord('a') - ord('A') | |
def my_title(title): | |
acc = "" | |
previous_letter = "" | |
for letter in title: | |
if ("a" <= letter <= "z") and not("a" <= previous_letter <= "z") and not("A" <= previous_letter <= "Z"): | |
letter = chr(ord(letter) - LOWER_CASE_TO_CAPITAL) | |
previous_letter = letter | |
acc += letter | |
return acc |
Et le voilà qui passe tous les tests et cela sans le "compteur" qui vous a arraché les yeux :)
Version très claire, et que je préfère même à la mienne (cf. commentaires du code d'Alexandre). Bravo!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
PS: ton programme échoue sur au moins un des nouveaux tests.