Created
August 13, 2014 11:08
-
-
Save annelisebouyer/22c3c68012fcc634882e to your computer and use it in GitHub Desktop.
kata#9AL-ED.py
This file contains 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
def get_my_password_table(sentence): | |
table_char=["" for i in range(0,26)] | |
for char in sentence: | |
i=ord(char)-ord("a") | |
if i in range(0,26): | |
table_char[i]=table_char[i]+char | |
return table_char | |
def get_my_password(sentence): | |
table_char=get_my_password_table(sentence) | |
##print table_char | |
return "".join(table_char) | |
def get_my_password_with_numbers(sentence): | |
password_with_numbers="" | |
my_first_password=get_my_password_table(sentence) | |
for chars in my_first_password: | |
nb_chars=len(chars) | |
if nb_chars>0: | |
password_with_numbers=password_with_numbers+str(nb_chars)+chars[0] | |
print password_with_numbers | |
return password_with_numbers | |
print get_my_password_with_numbers("monnouveaumotdepassefacebook") | |
assert get_my_password("when") == "ehnw", get_my_password("when") | |
assert get_my_password("wheen") == "eehnw", get_my_password("wheen") | |
assert get_my_password("when not studying nuclear physics, bambi likes to play beach volleyball.") == "aaaaabbbbcccdeeeeeghhhiiiiklllllllmnnnnooopprsssstttuuvwyyyy", get_my_password("when not studying nuclear physics, bambi likes to play beach volleyball.") | |
assert get_my_password_with_numbers("when") == "1e1h1n1w", get_my_password_with_numbers("when") | |
assert get_my_password_with_numbers("when not studying nuclear physics, bambi likes to play beach volleyball.") == "5a4b3c1d5e1g3h4i1k7l1m4n3o2p1r4s3t2u1v1w4y", get_my_password_with_numbers("when not studying nuclear physics, bambi likes to play beach volleyball.") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment