From 00c22a34ddc2918a1d71ff00e36c341428067c05 Mon Sep 17 00:00:00 2001 From: yauchuscom Date: Sun, 16 May 2021 13:18:42 +0300 Subject: [PATCH 01/35] Added censor function --- strings/censor.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 strings/censor.py diff --git a/strings/censor.py b/strings/censor.py new file mode 100644 index 000000000000..e69de29bb2d1 From 419434471455e53287360d75fdd85fd949d24066 Mon Sep 17 00:00:00 2001 From: yauchuscom Date: Mon, 17 May 2021 17:35:32 +0300 Subject: [PATCH 02/35] Added censor code --- strings/censor.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/strings/censor.py b/strings/censor.py index e69de29bb2d1..cbdd948a9033 100644 --- a/strings/censor.py +++ b/strings/censor.py @@ -0,0 +1,11 @@ +txt = input("Please enter the text from which you would like to censor a certain word: \n") +word = input("Please enter the word you would like to be censored from the text: \n") +txt_lst = txt.split() +for word1 in txt_lst: + if word1 == word: + txt_lst[txt_lst.index(word1)] = "*" * len(word1) +txt = "" +for word1 in txt_lst: + txt += word1 + " " +txt = txt[:-1] +print(txt) \ No newline at end of file From e7d4102bbb5a90ea144f9a5880a92722dc5cd20e Mon Sep 17 00:00:00 2001 From: Margaret <62753112+meg-1@users.noreply.github.com> Date: Mon, 17 May 2021 17:40:48 +0300 Subject: [PATCH 03/35] Added comments to the code --- strings/censor.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/strings/censor.py b/strings/censor.py index cbdd948a9033..5c629cf79a18 100644 --- a/strings/censor.py +++ b/strings/censor.py @@ -1,11 +1,15 @@ txt = input("Please enter the text from which you would like to censor a certain word: \n") word = input("Please enter the word you would like to be censored from the text: \n") txt_lst = txt.split() + +#here we loop through a list which consists of words from the text we should censor for word1 in txt_lst: if word1 == word: txt_lst[txt_lst.index(word1)] = "*" * len(word1) txt = "" + +#here we combine all of the split words in txt_lst into one string for word1 in txt_lst: txt += word1 + " " txt = txt[:-1] -print(txt) \ No newline at end of file +print(txt) From 93bd4acf6b7eeb2a856319837c3f854f0a574a11 Mon Sep 17 00:00:00 2001 From: yauchuscom Date: Sat, 22 May 2021 13:34:28 +0300 Subject: [PATCH 04/35] modified censor function --- strings/censor.py | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/strings/censor.py b/strings/censor.py index 5c629cf79a18..607dcd9a53d7 100644 --- a/strings/censor.py +++ b/strings/censor.py @@ -1,15 +1,14 @@ -txt = input("Please enter the text from which you would like to censor a certain word: \n") -word = input("Please enter the word you would like to be censored from the text: \n") -txt_lst = txt.split() +def censor(txt, word): + txt_lst = txt.split() + #here we loop through a list which consists of words from the text we should censor + for word1 in txt_lst: + if word1 == word: + txt_lst[txt_lst.index(word1)] = "*" * len(word1) + txt = "" + #here we combine all of the split words in txt_lst into one string + for word1 in txt_lst: + txt += word1 + " " + txt = txt[:-1] + print(txt) -#here we loop through a list which consists of words from the text we should censor -for word1 in txt_lst: - if word1 == word: - txt_lst[txt_lst.index(word1)] = "*" * len(word1) -txt = "" - -#here we combine all of the split words in txt_lst into one string -for word1 in txt_lst: - txt += word1 + " " -txt = txt[:-1] -print(txt) +censor("one two three", "one") \ No newline at end of file From b7142782ae3376c5e66f2adf025d8e4a57e3f0d7 Mon Sep 17 00:00:00 2001 From: yauchuscom Date: Sun, 1 Aug 2021 23:05:45 +0300 Subject: [PATCH 05/35] added decrypt function --- strings/decrypt.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 strings/decrypt.py diff --git a/strings/decrypt.py b/strings/decrypt.py new file mode 100644 index 000000000000..478226af5f17 --- /dev/null +++ b/strings/decrypt.py @@ -0,0 +1,27 @@ +def decrypt(txt, symbol): + #here we split the string we need to decypher into a list + txt_lst = txt.split() + res_str = "" + #we create a for loop which loops through the newly created list + for word1 in txt_lst: + #here we convert the current word we got through the loop into a list of charachters + word1_lst = list(word1) + #we loop through each charachter in the newly created list of charachters form the word we are looping throuh + for char1 in word1_lst: + #we set a condition, where if the symbol the loop is currently on corresponds to the symbol we need to remove, we stop on it and examine it + if char1 == symbol: + #we find the charachters index from the word + indx = word1.index(char1) + #we remove the list (the list which contains every element and characahter from the word we are looping throuh) element with the same index from the list. + word1_lst[indx] = "" + res_wrd = "" + #we loop throuh the list containing all the charachters from the word, and append those charachters to a new string + for char1 in word1_lst: + res_wrd += char1 + #here we add the newly created, decyphered word to a new string which will contain our full result + res_str += res_wrd + " " + res_str = res_str[:-1] + #and here we print out the final result + print(res_str) + +decrypt("o$ne t$wo three$", "$") \ No newline at end of file From c879c7f589a41cf9a669fda94a01c38afd04484b Mon Sep 17 00:00:00 2001 From: yauchuscom Date: Wed, 4 Aug 2021 14:24:38 +0300 Subject: [PATCH 06/35] added cypher and decypher functions, deleted censor and decrypt functions --- strings/cypher_txt.py | 51 +++++++++++++++++++++++++++++++++++++++++ strings/decypher_txt.py | 49 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 strings/cypher_txt.py create mode 100644 strings/decypher_txt.py diff --git a/strings/cypher_txt.py b/strings/cypher_txt.py new file mode 100644 index 000000000000..45abc0896e94 --- /dev/null +++ b/strings/cypher_txt.py @@ -0,0 +1,51 @@ +def cypher_mesage(txt): + alphabet_lower = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] + alphabet_upper = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', "X", 'Y', 'Z'] + + info = [] + for char in txt: + if (char.isalpha() == False): + info.append(2) + elif char.isupper() == True: + info.append(1) + else: + info.append(0) + + indx_lst=[] + for char in txt: + if (char.isalpha() == False): + indx_lst+=char + else: + if char.isupper() == True: + indx_lst.append(alphabet_upper.index(char)) + else: + indx_lst.append(alphabet_lower.index(char)) + + res_indx=[] + for char in indx_lst: + if type(char) == int: + if int(char) <= 2: + res_indx.append(26 + (int(char) - 3)) + else: + res_indx.append(int(char) - 3) + else: + res_indx+=char + + + res_str = "" + count = 0 + for char in res_indx: + if type(char) != int: + res_str += char + else: + if info[count] == 0: + res_str += str(alphabet_lower[int(char)]) + elif info[count] == 1: + res_str += str(alphabet_upper[int(char)]) + count+=1 + + print(res_str) + + + +code_mesage("xXyzabB!1234") \ No newline at end of file diff --git a/strings/decypher_txt.py b/strings/decypher_txt.py new file mode 100644 index 000000000000..509f9fc6963c --- /dev/null +++ b/strings/decypher_txt.py @@ -0,0 +1,49 @@ +def decode_mesage(txt): + alphabet_lower = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] + alphabet_upper = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', "X", 'Y', 'Z'] + + info = [] + for char in txt: + if (char.isalpha() == False): + info.append(2) + elif char.isupper() == True: + info.append(1) + else: + info.append(0) + + indx_lst=[] + for char in txt: + if (char.isalpha() == False): + indx_lst+=char + else: + if char.isupper() == True: + indx_lst.append(alphabet_upper.index(char)) + else: + indx_lst.append(alphabet_lower.index(char)) + + res_indx=[] + for char in indx_lst: + if type(char) == int: + if int(char) >= 23: + res_indx.append((int(char) - 23)) + else: + res_indx.append(int(char) + 3) + else: + res_indx+=char + + + res_str = "" + count = 0 + for char in res_indx: + if type(char) != int: + res_str += char + else: + if info[count] == 0: + res_str += str(alphabet_lower[int(char)]) + elif info[count] == 1: + res_str += str(alphabet_upper[int(char)]) + count+=1 + + print(res_str) + +print(decode_mesage("xyzab!1234")) \ No newline at end of file From e60dd6f96a3ec55e4ba148e316859a8d6b829658 Mon Sep 17 00:00:00 2001 From: Margaret <62753112+meg-1@users.noreply.github.com> Date: Wed, 4 Aug 2021 14:36:05 +0300 Subject: [PATCH 07/35] Deleted decrypt.py --- strings/decrypt.py | 27 --------------------------- 1 file changed, 27 deletions(-) delete mode 100644 strings/decrypt.py diff --git a/strings/decrypt.py b/strings/decrypt.py deleted file mode 100644 index 478226af5f17..000000000000 --- a/strings/decrypt.py +++ /dev/null @@ -1,27 +0,0 @@ -def decrypt(txt, symbol): - #here we split the string we need to decypher into a list - txt_lst = txt.split() - res_str = "" - #we create a for loop which loops through the newly created list - for word1 in txt_lst: - #here we convert the current word we got through the loop into a list of charachters - word1_lst = list(word1) - #we loop through each charachter in the newly created list of charachters form the word we are looping throuh - for char1 in word1_lst: - #we set a condition, where if the symbol the loop is currently on corresponds to the symbol we need to remove, we stop on it and examine it - if char1 == symbol: - #we find the charachters index from the word - indx = word1.index(char1) - #we remove the list (the list which contains every element and characahter from the word we are looping throuh) element with the same index from the list. - word1_lst[indx] = "" - res_wrd = "" - #we loop throuh the list containing all the charachters from the word, and append those charachters to a new string - for char1 in word1_lst: - res_wrd += char1 - #here we add the newly created, decyphered word to a new string which will contain our full result - res_str += res_wrd + " " - res_str = res_str[:-1] - #and here we print out the final result - print(res_str) - -decrypt("o$ne t$wo three$", "$") \ No newline at end of file From b3e0cb8b88617b4e62f6993ce24b62231ef1817f Mon Sep 17 00:00:00 2001 From: Margaret <62753112+meg-1@users.noreply.github.com> Date: Wed, 4 Aug 2021 14:36:45 +0300 Subject: [PATCH 08/35] Deleted censor.py --- strings/censor.py | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 strings/censor.py diff --git a/strings/censor.py b/strings/censor.py deleted file mode 100644 index 607dcd9a53d7..000000000000 --- a/strings/censor.py +++ /dev/null @@ -1,14 +0,0 @@ -def censor(txt, word): - txt_lst = txt.split() - #here we loop through a list which consists of words from the text we should censor - for word1 in txt_lst: - if word1 == word: - txt_lst[txt_lst.index(word1)] = "*" * len(word1) - txt = "" - #here we combine all of the split words in txt_lst into one string - for word1 in txt_lst: - txt += word1 + " " - txt = txt[:-1] - print(txt) - -censor("one two three", "one") \ No newline at end of file From 947f7d84c083e0ae941977c741d332e2b73d74c3 Mon Sep 17 00:00:00 2001 From: yauchuscom Date: Wed, 4 Aug 2021 14:44:20 +0300 Subject: [PATCH 09/35] edited the crypt and decrypt files --- strings/cypher_txt.py | 6 +----- strings/decypher_txt.py | 4 +--- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/strings/cypher_txt.py b/strings/cypher_txt.py index 45abc0896e94..338d2ec33f43 100644 --- a/strings/cypher_txt.py +++ b/strings/cypher_txt.py @@ -44,8 +44,4 @@ def cypher_mesage(txt): res_str += str(alphabet_upper[int(char)]) count+=1 - print(res_str) - - - -code_mesage("xXyzabB!1234") \ No newline at end of file + print(res_str) \ No newline at end of file diff --git a/strings/decypher_txt.py b/strings/decypher_txt.py index 509f9fc6963c..2f13ddd9a7d4 100644 --- a/strings/decypher_txt.py +++ b/strings/decypher_txt.py @@ -44,6 +44,4 @@ def decode_mesage(txt): res_str += str(alphabet_upper[int(char)]) count+=1 - print(res_str) - -print(decode_mesage("xyzab!1234")) \ No newline at end of file + print(res_str) \ No newline at end of file From daf21ad821d5462d47160c4efd6ca1ce572c772b Mon Sep 17 00:00:00 2001 From: Margaret <62753112+meg-1@users.noreply.github.com> Date: Wed, 4 Aug 2021 14:55:21 +0300 Subject: [PATCH 10/35] Update cypher_txt.py --- strings/cypher_txt.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/strings/cypher_txt.py b/strings/cypher_txt.py index 45abc0896e94..5aaeb6d0994d 100644 --- a/strings/cypher_txt.py +++ b/strings/cypher_txt.py @@ -45,7 +45,3 @@ def cypher_mesage(txt): count+=1 print(res_str) - - - -code_mesage("xXyzabB!1234") \ No newline at end of file From d3d8b29926119eb2a8b6eee5ce8dbef7f16cd64b Mon Sep 17 00:00:00 2001 From: Margaret <62753112+meg-1@users.noreply.github.com> Date: Wed, 4 Aug 2021 15:18:15 +0300 Subject: [PATCH 11/35] Remove the endline in cypher.py --- strings/cypher_txt.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/strings/cypher_txt.py b/strings/cypher_txt.py index 5aaeb6d0994d..3c23571f906c 100644 --- a/strings/cypher_txt.py +++ b/strings/cypher_txt.py @@ -43,5 +43,3 @@ def cypher_mesage(txt): elif info[count] == 1: res_str += str(alphabet_upper[int(char)]) count+=1 - - print(res_str) From 752c197dba6f158115372cbbe967fd8353ff026f Mon Sep 17 00:00:00 2001 From: Margaret <62753112+meg-1@users.noreply.github.com> Date: Wed, 4 Aug 2021 15:19:33 +0300 Subject: [PATCH 12/35] Removed the print at the end of decypher.py --- strings/decypher_txt.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/strings/decypher_txt.py b/strings/decypher_txt.py index 509f9fc6963c..aa97ac834ac0 100644 --- a/strings/decypher_txt.py +++ b/strings/decypher_txt.py @@ -43,7 +43,3 @@ def decode_mesage(txt): elif info[count] == 1: res_str += str(alphabet_upper[int(char)]) count+=1 - - print(res_str) - -print(decode_mesage("xyzab!1234")) \ No newline at end of file From f72431b07dae6a172e84d6041547858c17a75f8b Mon Sep 17 00:00:00 2001 From: yauchuscom Date: Wed, 18 Aug 2021 18:26:33 +0300 Subject: [PATCH 13/35] added 4 new algorithms --- strings/censor.py | 14 +++++++++++ strings/code_message.py | 51 +++++++++++++++++++++++++++++++++++++++ strings/decode_message.py | 49 +++++++++++++++++++++++++++++++++++++ strings/decrypt.py | 27 +++++++++++++++++++++ 4 files changed, 141 insertions(+) create mode 100644 strings/censor.py create mode 100644 strings/code_message.py create mode 100644 strings/decode_message.py create mode 100644 strings/decrypt.py diff --git a/strings/censor.py b/strings/censor.py new file mode 100644 index 000000000000..2481dbc9b7a6 --- /dev/null +++ b/strings/censor.py @@ -0,0 +1,14 @@ +def censor(txt, word) -> str: + txt_lst = txt.split() + #here we loop through a list which consists of words from the text we should censor + for index, word1 in enumerate(txt_lst): + if word1 == word: + txt_lst[index] = "*" * len(word1) + txt = "" + #here we combine all of the split words in txt_lst into one string + for word1 in txt_lst: + txt += word1 + " " + txt = txt[:-1] + print(txt) + +censor("one two three", "one") \ No newline at end of file diff --git a/strings/code_message.py b/strings/code_message.py new file mode 100644 index 000000000000..340c922f9764 --- /dev/null +++ b/strings/code_message.py @@ -0,0 +1,51 @@ +def code_mesage(txt) -> str: + alphabet_lower = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] + alphabet_upper = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', "X", 'Y', 'Z'] + + info = [] + for char in txt: + if (char.isalpha() == False): + info.append(2) + elif char.isupper() == True: + info.append(1) + else: + info.append(0) + + indx_lst=[] + for char in txt: + if (char.isalpha() == False): + indx_lst+=char + else: + if char.isupper() == True: + indx_lst.append(alphabet_upper.index(char)) + else: + indx_lst.append(alphabet_lower.index(char)) + + res_indx=[] + for char in indx_lst: + if type(char) == int: + if int(char) <= 2: + res_indx.append(26 + (int(char) - 3)) + else: + res_indx.append(int(char) - 3) + else: + res_indx+=char + + + res_str = "" + count = 0 + for char in res_indx: + if type(char) != int: + res_str += char + else: + if info[count] == 0: + res_str += str(alphabet_lower[int(char)]) + elif info[count] == 1: + res_str += str(alphabet_upper[int(char)]) + count+=1 + + print(res_str) + + + +code_mesage("abcde!1234") \ No newline at end of file diff --git a/strings/decode_message.py b/strings/decode_message.py new file mode 100644 index 000000000000..c229dd6a2882 --- /dev/null +++ b/strings/decode_message.py @@ -0,0 +1,49 @@ +def decode_mesage(txt) -> str: + alphabet_lower = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] + alphabet_upper = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', "X", 'Y', 'Z'] + + info = [] + for char in txt: + if (char.isalpha() == False): + info.append(2) + elif char.isupper() == True: + info.append(1) + else: + info.append(0) + + indx_lst=[] + for char in txt: + if (char.isalpha() == False): + indx_lst+=char + else: + if char.isupper() == True: + indx_lst.append(alphabet_upper.index(char)) + else: + indx_lst.append(alphabet_lower.index(char)) + + res_indx=[] + for char in indx_lst: + if type(char) == int: + if int(char) >= 23: + res_indx.append((int(char) - 23)) + else: + res_indx.append(int(char) + 3) + else: + res_indx+=char + + + res_str = "" + count = 0 + for char in res_indx: + if type(char) != int: + res_str += char + else: + if info[count] == 0: + res_str += str(alphabet_lower[int(char)]) + elif info[count] == 1: + res_str += str(alphabet_upper[int(char)]) + count+=1 + + print(res_str) + +print(decode_mesage("xyzab!1234")) \ No newline at end of file diff --git a/strings/decrypt.py b/strings/decrypt.py new file mode 100644 index 000000000000..3cbacbce0284 --- /dev/null +++ b/strings/decrypt.py @@ -0,0 +1,27 @@ +def decrypt(txt, symbol) -> str: + #here we split the string we need to decypher into a list + txt_lst = txt.split() + res_str = "" + #we create a for loop which loops through the newly created list + for word1 in txt_lst: + #here we convert the current word we got through the loop into a list of charachters + word1_lst = list(word1) + #we loop through each charachter in the newly created list of charachters form the word we are looping throuh + for char1 in word1_lst: + #we set a condition, where if the symbol the loop is currently on corresponds to the symbol we need to remove, we stop on it and examine it + if char1 == symbol: + #we find the charachters index from the word + indx = word1.index(char1) + #we remove the list (the list which contains every element and characahter from the word we are looping throuh) element with the same index from the list. + word1_lst[indx] = "" + res_wrd = "" + #we loop throuh the list containing all the charachters from the word, and append those charachters to a new string + for char1 in word1_lst: + res_wrd += char1 + #here we add the newly created, decyphered word to a new string which will contain our full result + res_str += res_wrd + " " + res_str = res_str[:-1] + #and here we print out the final result + print(res_str) + +decrypt("o$ne t$wo three$", "$") \ No newline at end of file From 4c891f484ed772a554d00fdaa1aac0443dfc4a31 Mon Sep 17 00:00:00 2001 From: yauchuscom Date: Wed, 25 Aug 2021 14:44:17 +0300 Subject: [PATCH 14/35] added tests to the four files --- strings/censor.py | 36 ++++++++++++++++++++++++------------ strings/code_message.py | 15 ++++++++++++--- strings/decode_message.py | 13 ++++++++++++- strings/decrypt.py | 13 ++++++++++++- 4 files changed, 60 insertions(+), 17 deletions(-) diff --git a/strings/censor.py b/strings/censor.py index 2481dbc9b7a6..de3c0b076c8b 100644 --- a/strings/censor.py +++ b/strings/censor.py @@ -1,14 +1,26 @@ def censor(txt, word) -> str: - txt_lst = txt.split() - #here we loop through a list which consists of words from the text we should censor - for index, word1 in enumerate(txt_lst): - if word1 == word: - txt_lst[index] = "*" * len(word1) - txt = "" - #here we combine all of the split words in txt_lst into one string - for word1 in txt_lst: - txt += word1 + " " - txt = txt[:-1] - print(txt) + """ + >>> censor("one two three", "one") + *** two three + >>> censor("email, password", "password") + email, ******** + >>> censor("pin: 2536", "2536") + pin: **** -censor("one two three", "one") \ No newline at end of file + """ + + txt_lst = txt.split() + #here we loop through a list which consists of words from the text we should censor + for index, word1 in enumerate(txt_lst): + if word1 == word: + txt_lst[index] = "*" * len(word1) + txt = "" + #here we combine all of the split words in txt_lst into one string + for word1 in txt_lst: + txt += word1 + " " + txt = txt[:-1] + print(txt) + +if __name__ == "__main__": + import doctest + doctest.testmod() \ No newline at end of file diff --git a/strings/code_message.py b/strings/code_message.py index 340c922f9764..ca40530cda24 100644 --- a/strings/code_message.py +++ b/strings/code_message.py @@ -1,4 +1,13 @@ def code_mesage(txt) -> str: + """ + >>> code_mesage("Def") + Abc + >>> code_mesage("bcF") + yzC + >>> code_mesage("qva") + nsx + + """ alphabet_lower = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] alphabet_upper = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', "X", 'Y', 'Z'] @@ -46,6 +55,6 @@ def code_mesage(txt) -> str: print(res_str) - - -code_mesage("abcde!1234") \ No newline at end of file +if __name__ == "__main__": + import doctest + doctest.testmod() \ No newline at end of file diff --git a/strings/decode_message.py b/strings/decode_message.py index c229dd6a2882..028bd2ff553e 100644 --- a/strings/decode_message.py +++ b/strings/decode_message.py @@ -1,4 +1,13 @@ def decode_mesage(txt) -> str: + """ + >>> decode_mesage("eFg") + hIj + >>> decode_mesage("yzC") + bcF + >>> decode_mesage("nsx") + qva + + """ alphabet_lower = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] alphabet_upper = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', "X", 'Y', 'Z'] @@ -46,4 +55,6 @@ def decode_mesage(txt) -> str: print(res_str) -print(decode_mesage("xyzab!1234")) \ No newline at end of file +if __name__ == "__main__": + import doctest + doctest.testmod() \ No newline at end of file diff --git a/strings/decrypt.py b/strings/decrypt.py index 3cbacbce0284..6d824653e790 100644 --- a/strings/decrypt.py +++ b/strings/decrypt.py @@ -1,4 +1,13 @@ def decrypt(txt, symbol) -> str: + """ + >>> decrypt("o$ne", "$") + one + >>> decrypt("dec@rypt", "@") + decrypt + >>> decrypt("p#ython cod#e", "#") + python code + + """ #here we split the string we need to decypher into a list txt_lst = txt.split() res_str = "" @@ -24,4 +33,6 @@ def decrypt(txt, symbol) -> str: #and here we print out the final result print(res_str) -decrypt("o$ne t$wo three$", "$") \ No newline at end of file +if __name__ == "__main__": + import doctest + doctest.testmod() \ No newline at end of file From c600b10545bc6a070198950f614cef948a5fde44 Mon Sep 17 00:00:00 2001 From: yauchuscom Date: Wed, 25 Aug 2021 14:54:01 +0300 Subject: [PATCH 15/35] added type hints for the function variables --- strings/censor.py | 2 +- strings/code_message.py | 2 +- strings/decode_message.py | 2 +- strings/decrypt.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/strings/censor.py b/strings/censor.py index de3c0b076c8b..fe10a08c5bc4 100644 --- a/strings/censor.py +++ b/strings/censor.py @@ -1,4 +1,4 @@ -def censor(txt, word) -> str: +def censor(txt: str, word: str) -> str: """ >>> censor("one two three", "one") *** two three diff --git a/strings/code_message.py b/strings/code_message.py index ca40530cda24..cb8603329115 100644 --- a/strings/code_message.py +++ b/strings/code_message.py @@ -1,4 +1,4 @@ -def code_mesage(txt) -> str: +def code_mesage(txt: str) -> str: """ >>> code_mesage("Def") Abc diff --git a/strings/decode_message.py b/strings/decode_message.py index 028bd2ff553e..9c100f7c2ec7 100644 --- a/strings/decode_message.py +++ b/strings/decode_message.py @@ -1,4 +1,4 @@ -def decode_mesage(txt) -> str: +def decode_mesage(txt: str) -> str: """ >>> decode_mesage("eFg") hIj diff --git a/strings/decrypt.py b/strings/decrypt.py index 6d824653e790..3535d2443a2c 100644 --- a/strings/decrypt.py +++ b/strings/decrypt.py @@ -1,4 +1,4 @@ -def decrypt(txt, symbol) -> str: +def decrypt(txt: str, symbol: str) -> str: """ >>> decrypt("o$ne", "$") one From 7a909e24a5bb5ba2d9e3a8582cad346613b9b1c3 Mon Sep 17 00:00:00 2001 From: Margaret <62753112+meg-1@users.noreply.github.com> Date: Sat, 25 Dec 2021 14:49:16 +0200 Subject: [PATCH 16/35] Deleted decode message --- strings/decode_message.py | 60 --------------------------------------- 1 file changed, 60 deletions(-) delete mode 100644 strings/decode_message.py diff --git a/strings/decode_message.py b/strings/decode_message.py deleted file mode 100644 index 9c100f7c2ec7..000000000000 --- a/strings/decode_message.py +++ /dev/null @@ -1,60 +0,0 @@ -def decode_mesage(txt: str) -> str: - """ - >>> decode_mesage("eFg") - hIj - >>> decode_mesage("yzC") - bcF - >>> decode_mesage("nsx") - qva - - """ - alphabet_lower = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] - alphabet_upper = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', "X", 'Y', 'Z'] - - info = [] - for char in txt: - if (char.isalpha() == False): - info.append(2) - elif char.isupper() == True: - info.append(1) - else: - info.append(0) - - indx_lst=[] - for char in txt: - if (char.isalpha() == False): - indx_lst+=char - else: - if char.isupper() == True: - indx_lst.append(alphabet_upper.index(char)) - else: - indx_lst.append(alphabet_lower.index(char)) - - res_indx=[] - for char in indx_lst: - if type(char) == int: - if int(char) >= 23: - res_indx.append((int(char) - 23)) - else: - res_indx.append(int(char) + 3) - else: - res_indx+=char - - - res_str = "" - count = 0 - for char in res_indx: - if type(char) != int: - res_str += char - else: - if info[count] == 0: - res_str += str(alphabet_lower[int(char)]) - elif info[count] == 1: - res_str += str(alphabet_upper[int(char)]) - count+=1 - - print(res_str) - -if __name__ == "__main__": - import doctest - doctest.testmod() \ No newline at end of file From f5b5411a2126df879ed757bbd2944f54a41ccc23 Mon Sep 17 00:00:00 2001 From: Margaret <62753112+meg-1@users.noreply.github.com> Date: Sat, 25 Dec 2021 14:49:38 +0200 Subject: [PATCH 17/35] Deleted code message --- strings/code_message.py | 60 ----------------------------------------- 1 file changed, 60 deletions(-) delete mode 100644 strings/code_message.py diff --git a/strings/code_message.py b/strings/code_message.py deleted file mode 100644 index cb8603329115..000000000000 --- a/strings/code_message.py +++ /dev/null @@ -1,60 +0,0 @@ -def code_mesage(txt: str) -> str: - """ - >>> code_mesage("Def") - Abc - >>> code_mesage("bcF") - yzC - >>> code_mesage("qva") - nsx - - """ - alphabet_lower = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] - alphabet_upper = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', "X", 'Y', 'Z'] - - info = [] - for char in txt: - if (char.isalpha() == False): - info.append(2) - elif char.isupper() == True: - info.append(1) - else: - info.append(0) - - indx_lst=[] - for char in txt: - if (char.isalpha() == False): - indx_lst+=char - else: - if char.isupper() == True: - indx_lst.append(alphabet_upper.index(char)) - else: - indx_lst.append(alphabet_lower.index(char)) - - res_indx=[] - for char in indx_lst: - if type(char) == int: - if int(char) <= 2: - res_indx.append(26 + (int(char) - 3)) - else: - res_indx.append(int(char) - 3) - else: - res_indx+=char - - - res_str = "" - count = 0 - for char in res_indx: - if type(char) != int: - res_str += char - else: - if info[count] == 0: - res_str += str(alphabet_lower[int(char)]) - elif info[count] == 1: - res_str += str(alphabet_upper[int(char)]) - count+=1 - - print(res_str) - -if __name__ == "__main__": - import doctest - doctest.testmod() \ No newline at end of file From bc8388c9d61f9d495fef5352fdb63b41cae1377b Mon Sep 17 00:00:00 2001 From: Margaret <62753112+meg-1@users.noreply.github.com> Date: Sat, 29 Jan 2022 14:56:33 +0200 Subject: [PATCH 18/35] Welford average algorithm --- maths/average_welford.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 maths/average_welford.py diff --git a/maths/average_welford.py b/maths/average_welford.py new file mode 100644 index 000000000000..2fe94116d9a4 --- /dev/null +++ b/maths/average_welford.py @@ -0,0 +1,21 @@ +def average_welford(values): + """ + >>> average_welford([1, 2, 3, 4, 5]) + 3.0 + >>> average_welford([1.2329435, 2.209462409, 3.230925, 4.47626462, 5.2938759204]) + 3.2886942898799996 + >>> average_welford([-57386462.2329435, 2246262.209462409, 4632463.230925, 856737354.47626462, -243664265.2938759204]) + 112513070.4779665 + """ + avg = 0.0 + """while looping through the list, + we calculate the average of the + current element and the average + of the elements before it""" + for index in range(0, len(values)): + avg += (values[index]-avg)/(index+1) + return avg + +if __name__ == "__main__": + import doctest + doctest.testmod() \ No newline at end of file From 9be479e9ac273131d47da5602f83cfb8e41babc3 Mon Sep 17 00:00:00 2001 From: Margaret <62753112+meg-1@users.noreply.github.com> Date: Wed, 9 Feb 2022 17:31:38 +0200 Subject: [PATCH 19/35] added average welford algorithm --- maths/average_welford.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maths/average_welford.py b/maths/average_welford.py index 2fe94116d9a4..2aafb18ab936 100644 --- a/maths/average_welford.py +++ b/maths/average_welford.py @@ -1,4 +1,4 @@ -def average_welford(values): +def average_welford(values: list) -> float: """ >>> average_welford([1, 2, 3, 4, 5]) 3.0 From f3fb7e64e046b38f6e5df70da007620115195b53 Mon Sep 17 00:00:00 2001 From: Margaret <62753112+meg-1@users.noreply.github.com> Date: Sat, 19 Mar 2022 14:56:43 +0200 Subject: [PATCH 20/35] is_narcissistic added --- maths/is_narcissistic.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 maths/is_narcissistic.py diff --git a/maths/is_narcissistic.py b/maths/is_narcissistic.py new file mode 100644 index 000000000000..047a1cc41937 --- /dev/null +++ b/maths/is_narcissistic.py @@ -0,0 +1,24 @@ +def is_narcissistic(i: int) -> bool: + + """ + >>> is_narcissistic(1527) + False + >>> is_narcissistic(-1527) + False + >>> is_narcissistic(153) + True + >>> is_narcissistic("153") + True + """ + + """In number theory, a narcissistic number is a number that is + the sum of its own digits each raised to the power of the number of digits. + this alogrithm finds out if given number 'i' is narcissistic or not""" + + i = abs(int(i)) + return sum([int(char)**len(str(i)) for char in str(i)]) == i + + +if __name__ == "__main__": + import doctest + doctest.testmod() \ No newline at end of file From d00d1356838fdd0cb0857f0b42066c197e279610 Mon Sep 17 00:00:00 2001 From: Margaret <62753112+meg-1@users.noreply.github.com> Date: Wed, 23 Mar 2022 17:43:11 +0200 Subject: [PATCH 21/35] added a descriptive name --- maths/is_narcissistic.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/maths/is_narcissistic.py b/maths/is_narcissistic.py index 047a1cc41937..490c344e4b19 100644 --- a/maths/is_narcissistic.py +++ b/maths/is_narcissistic.py @@ -1,4 +1,4 @@ -def is_narcissistic(i: int) -> bool: +def is_narcissistic(num: int) -> bool: """ >>> is_narcissistic(1527) @@ -13,10 +13,10 @@ def is_narcissistic(i: int) -> bool: """In number theory, a narcissistic number is a number that is the sum of its own digits each raised to the power of the number of digits. - this alogrithm finds out if given number 'i' is narcissistic or not""" + this alogrithm finds out if given number 'num' is narcissistic or not""" - i = abs(int(i)) - return sum([int(char)**len(str(i)) for char in str(i)]) == i + num = abs(int(num)) + return sum([int(char)**len(str(num)) for char in str(num)]) == num if __name__ == "__main__": From b3b3cfa83cda21604c9a2f4d978d110666901692 Mon Sep 17 00:00:00 2001 From: Margaret <62753112+meg-1@users.noreply.github.com> Date: Wed, 23 Mar 2022 17:46:44 +0200 Subject: [PATCH 22/35] added max_sectors algorithm --- maths/max_sectors.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 maths/max_sectors.py diff --git a/maths/max_sectors.py b/maths/max_sectors.py new file mode 100644 index 000000000000..17fb0256096e --- /dev/null +++ b/maths/max_sectors.py @@ -0,0 +1,19 @@ +def max_sectors(num_cuts: float) -> float: + """ + >>> max_sectors(54) + 1486.0 + >>> max_sectors(7) + 29.0 + >>> max_sectors(22.5) + 265.375 + >>> max_sectors(-222) + -1 + """ + + """here we use a formula to figure out what is the maximum + amount of sectors a circle can be divided by if cut 'num_cuts' times""" + return ((num_cuts+2+num_cuts**2)*(1/2)) if num_cuts >= 0 else -1 + + if __name__ == "__main__": + import doctest + doctest.testmod() \ No newline at end of file From 6a3908712a4fd3524f8cdf3954860096b28e76f7 Mon Sep 17 00:00:00 2001 From: Margaret <62753112+meg-1@users.noreply.github.com> Date: Wed, 23 Mar 2022 17:51:01 +0200 Subject: [PATCH 23/35] added find_unique --- searches/find_unique.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 searches/find_unique.py diff --git a/searches/find_unique.py b/searches/find_unique.py new file mode 100644 index 000000000000..a2deee9881a8 --- /dev/null +++ b/searches/find_unique.py @@ -0,0 +1,19 @@ +def find_unique(arr: list) -> float: + """ + >>> find_unique([1, 2, 1, 1, 1, 1]) + 2 + >>> find_unique([12, 12, 12, 12, 12, 76]) + 76 + >>> find_unique([["one", "one"], ["one", "one"], ["one", "two"], ["one", "one"]]) + ['one', 'two'] + """ + + """this algorithm finds and returns a unique element + in a series of given elements.""" + + arr = sorted(arr) + return arr[-1] if arr[0] == arr[1] else arr[0] + +if __name__ == '__main__': + import doctest + doctest.testmod() \ No newline at end of file From dead6ebeafb14d153839c1a4c90e4eec883a0c3f Mon Sep 17 00:00:00 2001 From: Margaret <62753112+meg-1@users.noreply.github.com> Date: Wed, 23 Mar 2022 17:53:34 +0200 Subject: [PATCH 24/35] added wave algorithm --- strings/wave.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 strings/wave.py diff --git a/strings/wave.py b/strings/wave.py new file mode 100644 index 000000000000..2d70ed905ba9 --- /dev/null +++ b/strings/wave.py @@ -0,0 +1,19 @@ +def wave(txt: str) -> list: + """ + >>> wave('wave algorithm') + ['Wave algorithm', 'wAve algorithm', 'waVe algorithm', 'wavE algorithm', 'wave Algorithm', 'wave aLgorithm', 'wave alGorithm', 'wave algOrithm', 'wave algoRithm', 'wave algorIthm', 'wave algoriThm', 'wave algoritHm', 'wave algorithM'] + >>> wave('one') + ['One', 'oNe', 'onE'] + >>> wave('book') + ['Book', 'bOok', 'boOk', 'booK'] + """ + + """this algorithm returns a so called 'wave' of + a given string [ a list of each of it's capitalized + charachters one by one??? ]""" + + return [txt[:a] + txt[a].upper() + txt[a+1:] for a in range(len(txt)) if txt[a].isalpha()] + +if __name__ == '__main__': + import doctest + doctest.testmod() \ No newline at end of file From aac02db55c827bd1d4f0a5d81270308cb90fd354 Mon Sep 17 00:00:00 2001 From: Margaret <62753112+meg-1@users.noreply.github.com> Date: Sat, 16 Apr 2022 14:49:19 +0300 Subject: [PATCH 25/35] deleting average_welford [ in the wrong pr ] --- maths/average_welford.py | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 maths/average_welford.py diff --git a/maths/average_welford.py b/maths/average_welford.py deleted file mode 100644 index 2aafb18ab936..000000000000 --- a/maths/average_welford.py +++ /dev/null @@ -1,21 +0,0 @@ -def average_welford(values: list) -> float: - """ - >>> average_welford([1, 2, 3, 4, 5]) - 3.0 - >>> average_welford([1.2329435, 2.209462409, 3.230925, 4.47626462, 5.2938759204]) - 3.2886942898799996 - >>> average_welford([-57386462.2329435, 2246262.209462409, 4632463.230925, 856737354.47626462, -243664265.2938759204]) - 112513070.4779665 - """ - avg = 0.0 - """while looping through the list, - we calculate the average of the - current element and the average - of the elements before it""" - for index in range(0, len(values)): - avg += (values[index]-avg)/(index+1) - return avg - -if __name__ == "__main__": - import doctest - doctest.testmod() \ No newline at end of file From c4e0249b746e65a7cf54c8f7c0ddbeb691e17e74 Mon Sep 17 00:00:00 2001 From: Margaret <62753112+meg-1@users.noreply.github.com> Date: Sat, 16 Apr 2022 14:49:51 +0300 Subject: [PATCH 26/35] deleting is_narcissistic [ is in the wrong pr ] --- maths/is_narcissistic.py | 24 ------------------------ 1 file changed, 24 deletions(-) delete mode 100644 maths/is_narcissistic.py diff --git a/maths/is_narcissistic.py b/maths/is_narcissistic.py deleted file mode 100644 index 490c344e4b19..000000000000 --- a/maths/is_narcissistic.py +++ /dev/null @@ -1,24 +0,0 @@ -def is_narcissistic(num: int) -> bool: - - """ - >>> is_narcissistic(1527) - False - >>> is_narcissistic(-1527) - False - >>> is_narcissistic(153) - True - >>> is_narcissistic("153") - True - """ - - """In number theory, a narcissistic number is a number that is - the sum of its own digits each raised to the power of the number of digits. - this alogrithm finds out if given number 'num' is narcissistic or not""" - - num = abs(int(num)) - return sum([int(char)**len(str(num)) for char in str(num)]) == num - - -if __name__ == "__main__": - import doctest - doctest.testmod() \ No newline at end of file From ca22ab86e53b5032c6955bf74b6190e5d7f2beaa Mon Sep 17 00:00:00 2001 From: Margaret <62753112+meg-1@users.noreply.github.com> Date: Sat, 16 Apr 2022 14:50:06 +0300 Subject: [PATCH 27/35] deleting max_sectors [ is in the wrong pr ] --- maths/max_sectors.py | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 maths/max_sectors.py diff --git a/maths/max_sectors.py b/maths/max_sectors.py deleted file mode 100644 index 17fb0256096e..000000000000 --- a/maths/max_sectors.py +++ /dev/null @@ -1,19 +0,0 @@ -def max_sectors(num_cuts: float) -> float: - """ - >>> max_sectors(54) - 1486.0 - >>> max_sectors(7) - 29.0 - >>> max_sectors(22.5) - 265.375 - >>> max_sectors(-222) - -1 - """ - - """here we use a formula to figure out what is the maximum - amount of sectors a circle can be divided by if cut 'num_cuts' times""" - return ((num_cuts+2+num_cuts**2)*(1/2)) if num_cuts >= 0 else -1 - - if __name__ == "__main__": - import doctest - doctest.testmod() \ No newline at end of file From b29c043cc298e1dcaefab25ecbf718285c304709 Mon Sep 17 00:00:00 2001 From: Margaret <62753112+meg-1@users.noreply.github.com> Date: Sat, 16 Apr 2022 14:50:20 +0300 Subject: [PATCH 28/35] deleting find_unique [ is in the wrong pr ] --- searches/find_unique.py | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 searches/find_unique.py diff --git a/searches/find_unique.py b/searches/find_unique.py deleted file mode 100644 index a2deee9881a8..000000000000 --- a/searches/find_unique.py +++ /dev/null @@ -1,19 +0,0 @@ -def find_unique(arr: list) -> float: - """ - >>> find_unique([1, 2, 1, 1, 1, 1]) - 2 - >>> find_unique([12, 12, 12, 12, 12, 76]) - 76 - >>> find_unique([["one", "one"], ["one", "one"], ["one", "two"], ["one", "one"]]) - ['one', 'two'] - """ - - """this algorithm finds and returns a unique element - in a series of given elements.""" - - arr = sorted(arr) - return arr[-1] if arr[0] == arr[1] else arr[0] - -if __name__ == '__main__': - import doctest - doctest.testmod() \ No newline at end of file From 2db16b2f4d522ecbf8ec7ab86a0e6cfcb3a8cc4d Mon Sep 17 00:00:00 2001 From: Margaret <62753112+meg-1@users.noreply.github.com> Date: Sat, 16 Apr 2022 14:50:38 +0300 Subject: [PATCH 29/35] deleting censor [ is in the wrong pr ] --- strings/censor.py | 26 -------------------------- 1 file changed, 26 deletions(-) delete mode 100644 strings/censor.py diff --git a/strings/censor.py b/strings/censor.py deleted file mode 100644 index fe10a08c5bc4..000000000000 --- a/strings/censor.py +++ /dev/null @@ -1,26 +0,0 @@ -def censor(txt: str, word: str) -> str: - """ - >>> censor("one two three", "one") - *** two three - >>> censor("email, password", "password") - email, ******** - >>> censor("pin: 2536", "2536") - pin: **** - - """ - - txt_lst = txt.split() - #here we loop through a list which consists of words from the text we should censor - for index, word1 in enumerate(txt_lst): - if word1 == word: - txt_lst[index] = "*" * len(word1) - txt = "" - #here we combine all of the split words in txt_lst into one string - for word1 in txt_lst: - txt += word1 + " " - txt = txt[:-1] - print(txt) - -if __name__ == "__main__": - import doctest - doctest.testmod() \ No newline at end of file From 9e954dbf2f9fd9ece52d9f1f8c193f65bb62da54 Mon Sep 17 00:00:00 2001 From: Margaret <62753112+meg-1@users.noreply.github.com> Date: Sat, 16 Apr 2022 14:50:53 +0300 Subject: [PATCH 30/35] deleting decrypt [ is in the wrong pr ] --- strings/decrypt.py | 38 -------------------------------------- 1 file changed, 38 deletions(-) delete mode 100644 strings/decrypt.py diff --git a/strings/decrypt.py b/strings/decrypt.py deleted file mode 100644 index 3535d2443a2c..000000000000 --- a/strings/decrypt.py +++ /dev/null @@ -1,38 +0,0 @@ -def decrypt(txt: str, symbol: str) -> str: - """ - >>> decrypt("o$ne", "$") - one - >>> decrypt("dec@rypt", "@") - decrypt - >>> decrypt("p#ython cod#e", "#") - python code - - """ - #here we split the string we need to decypher into a list - txt_lst = txt.split() - res_str = "" - #we create a for loop which loops through the newly created list - for word1 in txt_lst: - #here we convert the current word we got through the loop into a list of charachters - word1_lst = list(word1) - #we loop through each charachter in the newly created list of charachters form the word we are looping throuh - for char1 in word1_lst: - #we set a condition, where if the symbol the loop is currently on corresponds to the symbol we need to remove, we stop on it and examine it - if char1 == symbol: - #we find the charachters index from the word - indx = word1.index(char1) - #we remove the list (the list which contains every element and characahter from the word we are looping throuh) element with the same index from the list. - word1_lst[indx] = "" - res_wrd = "" - #we loop throuh the list containing all the charachters from the word, and append those charachters to a new string - for char1 in word1_lst: - res_wrd += char1 - #here we add the newly created, decyphered word to a new string which will contain our full result - res_str += res_wrd + " " - res_str = res_str[:-1] - #and here we print out the final result - print(res_str) - -if __name__ == "__main__": - import doctest - doctest.testmod() \ No newline at end of file From 3d693588aeb0c8a45f8f02d1d1c5783289c52f73 Mon Sep 17 00:00:00 2001 From: Margaret <62753112+meg-1@users.noreply.github.com> Date: Wed, 18 May 2022 17:23:45 +0300 Subject: [PATCH 31/35] fixed wave.py fixed indentation and followed the bots reccomendations --- strings/wave.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/strings/wave.py b/strings/wave.py index 2d70ed905ba9..1494e961eb3e 100644 --- a/strings/wave.py +++ b/strings/wave.py @@ -1,19 +1,24 @@ def wave(txt: str) -> list: - """ + """ >>> wave('wave algorithm') ['Wave algorithm', 'wAve algorithm', 'waVe algorithm', 'wavE algorithm', 'wave Algorithm', 'wave aLgorithm', 'wave alGorithm', 'wave algOrithm', 'wave algoRithm', 'wave algorIthm', 'wave algoriThm', 'wave algoritHm', 'wave algorithM'] >>> wave('one') ['One', 'oNe', 'onE'] >>> wave('book') ['Book', 'bOok', 'boOk', 'booK'] - """ + """ - """this algorithm returns a so called 'wave' of - a given string [ a list of each of it's capitalized - charachters one by one??? ]""" + """this algorithm returns a so called 'wave' of + a given string [ a list of each of it's capitalized + charachters one by one??? ]""" - return [txt[:a] + txt[a].upper() + txt[a+1:] for a in range(len(txt)) if txt[a].isalpha()] + return [ + txt[:a] + txt[a].upper() + txt[a + 1 :] + for a in range(len(txt)) + if txt[a].isalpha() + ] if __name__ == '__main__': import doctest - doctest.testmod() \ No newline at end of file + + doctest.testmod() From aea79cd629774db7bb785d2b7a0cef054ffc7906 Mon Sep 17 00:00:00 2001 From: Margaret <62753112+meg-1@users.noreply.github.com> Date: Wed, 18 May 2022 17:28:44 +0300 Subject: [PATCH 32/35] fixed wave.py again --- strings/wave.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strings/wave.py b/strings/wave.py index 1494e961eb3e..5b0bd35b02eb 100644 --- a/strings/wave.py +++ b/strings/wave.py @@ -18,7 +18,7 @@ def wave(txt: str) -> list: if txt[a].isalpha() ] -if __name__ == '__main__': +if __name__ == "__main__": import doctest doctest.testmod() From c136c31903307cdc86063421dc9d6ab97ca16b09 Mon Sep 17 00:00:00 2001 From: Margaret <62753112+meg-1@users.noreply.github.com> Date: Wed, 18 May 2022 17:49:39 +0300 Subject: [PATCH 33/35] fixing wave.py for the third time. --- strings/wave.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/strings/wave.py b/strings/wave.py index 5b0bd35b02eb..05e07f58ad72 100644 --- a/strings/wave.py +++ b/strings/wave.py @@ -18,7 +18,6 @@ def wave(txt: str) -> list: if txt[a].isalpha() ] + if __name__ == "__main__": - import doctest - - doctest.testmod() + __import__("doctest").testmod() From b8a2864952bfcfa2eeaeb34c6e189d84c3cc6712 Mon Sep 17 00:00:00 2001 From: Margaret <62753112+meg-1@users.noreply.github.com> Date: Wed, 25 May 2022 17:07:13 +0300 Subject: [PATCH 34/35] fixing wave.py --- strings/wave.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/strings/wave.py b/strings/wave.py index 05e07f58ad72..cb99d6f70e22 100644 --- a/strings/wave.py +++ b/strings/wave.py @@ -1,7 +1,7 @@ def wave(txt: str) -> list: """ - >>> wave('wave algorithm') - ['Wave algorithm', 'wAve algorithm', 'waVe algorithm', 'wavE algorithm', 'wave Algorithm', 'wave aLgorithm', 'wave alGorithm', 'wave algOrithm', 'wave algoRithm', 'wave algorIthm', 'wave algoriThm', 'wave algoritHm', 'wave algorithM'] + >>> wave('cat') + ['Cat', 'cAt', 'caT'] >>> wave('one') ['One', 'oNe', 'onE'] >>> wave('book') @@ -10,7 +10,7 @@ def wave(txt: str) -> list: """this algorithm returns a so called 'wave' of a given string [ a list of each of it's capitalized - charachters one by one??? ]""" + characters one by one??? ]""" return [ txt[:a] + txt[a].upper() + txt[a + 1 :] From aafe75685f28944c89aae4f0fcd6243eaa62c669 Mon Sep 17 00:00:00 2001 From: Margaret <62753112+meg-1@users.noreply.github.com> Date: Wed, 22 Jun 2022 17:02:16 +0300 Subject: [PATCH 35/35] merging strings/wave.py merging the suggestion Co-authored-by: John Law --- strings/wave.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/strings/wave.py b/strings/wave.py index cb99d6f70e22..69d534432420 100644 --- a/strings/wave.py +++ b/strings/wave.py @@ -1,5 +1,6 @@ def wave(txt: str) -> list: """ + Returns a so called 'wave' of a given string >>> wave('cat') ['Cat', 'cAt', 'caT'] >>> wave('one') @@ -8,10 +9,6 @@ def wave(txt: str) -> list: ['Book', 'bOok', 'boOk', 'booK'] """ - """this algorithm returns a so called 'wave' of - a given string [ a list of each of it's capitalized - characters one by one??? ]""" - return [ txt[:a] + txt[a].upper() + txt[a + 1 :] for a in range(len(txt))