From 0e5da5a08105ac626778f40f9e65001106e13696 Mon Sep 17 00:00:00 2001 From: Chaitanya Date: Thu, 11 Apr 2024 03:42:33 +0530 Subject: [PATCH 1/5] hello World #1 --- practice/hello-world/hello_world.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/practice/hello-world/hello_world.py b/practice/hello-world/hello_world.py index adaa6c2..d695ea1 100644 --- a/practice/hello-world/hello_world.py +++ b/practice/hello-world/hello_world.py @@ -1,2 +1,2 @@ def hello(): - return 'Goodbye, Mars!' + return 'Hello, World!' From 95931877024fdd8519820db0b0e83f9b8c16a9e0 Mon Sep 17 00:00:00 2001 From: Chaitanya Date: Thu, 11 Apr 2024 23:48:39 +0530 Subject: [PATCH 2/5] Revert "hello World #1" This reverts commit 0e5da5a08105ac626778f40f9e65001106e13696. --- practice/hello-world/hello_world.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/practice/hello-world/hello_world.py b/practice/hello-world/hello_world.py index d695ea1..adaa6c2 100644 --- a/practice/hello-world/hello_world.py +++ b/practice/hello-world/hello_world.py @@ -1,2 +1,2 @@ def hello(): - return 'Hello, World!' + return 'Goodbye, Mars!' From 8382745dc65b26fd8506a00f8e154c2c514e5ad3 Mon Sep 17 00:00:00 2001 From: Chaitanya Date: Mon, 15 Apr 2024 00:09:26 +0530 Subject: [PATCH 3/5] pig-latin --- .../__pycache__/pig_latin.cpython-39.pyc | Bin 0 -> 648 bytes ...pig_latin_test.cpython-39-pytest-6.2.4.pyc | Bin 0 -> 5025 bytes practice/pig-latin/pig_latin.py | 18 +++++++++++++++++- 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 practice/pig-latin/__pycache__/pig_latin.cpython-39.pyc create mode 100644 practice/pig-latin/__pycache__/pig_latin_test.cpython-39-pytest-6.2.4.pyc diff --git a/practice/pig-latin/__pycache__/pig_latin.cpython-39.pyc b/practice/pig-latin/__pycache__/pig_latin.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000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UCDkh4E#o-nLCUp~n2G`qgCmJ=r1Ry33(fIiuH-@S0IySSR3>hxsn8Ga z2fAsuhEb*bT>C?cDu1YIpM<@su1~)^Cyph4ewJSU8w)SYQZ3cDmC5{ZHsdq)Z05Z& z%vmcR*2U(%Q_mvhsYF9K(Nd!o9z#`9|9vz6|L5o1n}y4HB!-gnVuABv z3>kLCiyp_^LxhtniZ+eZB0-N}nP7$BBEcmBN@o>qYN*Qulr5@tf(-&n$JAAVYXp?k zsOtoj8K^$NO#=G#u4MdW?oVmIY9i3R(+3Ey?KWrqD_d?a7VfJo2yycxEqZ%N&d+O` zJjrPocP2Y5K^*NUd8`60i|+ZUqH}g`0UJ+7T@`K?1sGDPX5Hj$N2T1HDcqNMb{}V> Yy!(d?74DalvHr>-SG3)6tI>1*1pvGS5dZ)H literal 0 HcmV?d00001 diff --git a/practice/pig-latin/pig_latin.py b/practice/pig-latin/pig_latin.py index dda3f07..ade63c1 100644 --- a/practice/pig-latin/pig_latin.py +++ b/practice/pig-latin/pig_latin.py @@ -1,2 +1,18 @@ def translate(text): - pass + VOWELS = {"a", "e", "i", "o", "u"} + VOWELS_Y = {"a", "e", "i", "o", "u", "y"} + SPECIALS = {"xr", "yt"} + piggyfied = [] + + for word in text.split(): + if word[0] in VOWELS or word[0:2] in SPECIALS: + piggyfied.append(word + "ay") + continue + + for pos in range(1, len(word)): + if word[pos] in VOWELS_Y: + pos += 1 if word[pos] == 'u' and word[pos - 1] == "q" else 0 + piggyfied.append(word[pos:] + word[:pos] + "ay") + break + + return " ".join(piggyfied) From 3b4b173f6c0ea84ef10488526a58a2c0dbd4687a Mon Sep 17 00:00:00 2001 From: Chaitanya Date: Mon, 22 Apr 2024 03:07:10 +0530 Subject: [PATCH 4/5] removed cache files --- .../__pycache__/pig_latin.cpython-39.pyc | Bin 648 -> 0 bytes .../pig_latin_test.cpython-39-pytest-6.2.4.pyc | Bin 5025 -> 0 bytes 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 practice/pig-latin/__pycache__/pig_latin.cpython-39.pyc delete mode 100644 practice/pig-latin/__pycache__/pig_latin_test.cpython-39-pytest-6.2.4.pyc diff --git a/practice/pig-latin/__pycache__/pig_latin.cpython-39.pyc b/practice/pig-latin/__pycache__/pig_latin.cpython-39.pyc deleted file mode 100644 index 6b30ebc56c539334e87e0e48ca811aa997168ff6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 648 zcmYjNzi-n(6n^jQbDWYgAfQyrP*oks04oTg2$Xa{LIugF2+L5pzH91|+RoW6v2>ma z{{b^f#Ka%M${%nmQ)V_M-WiH|r}yJ~?|b*%UA(@&2DH9!_m2Vw@Y8~;i)!$Mtn85! zAn+rEAXoqcCqXJ*t_~$W*@&$CLGGBiU$H@oj3N_`aF1EzOrUW!EMN&^c>AT{nhU-O z8qc8|+gx~`7-8oe)GO^SkZPR`SR%q~r((jd9L+EAg3*!jINK4|7Or-eNU!bf4LQBaU~KTr zpfs2o%!eM;l>G-~KT0_*rB<#5mLIaY3RzvPD2J8hgepM4`}^VeQM4ayjdCHQNtq{+oJ*CY(q4my!mTbT7 zzHPDvuwPi)&fnOR^?chdx>|`S4TY8-ovI!UtnA@0{S!f!w`2{lq4CaQ%}KYc1rD^a z?m!1zr;ufc8j6!|jTfxF08U>oisufu(KfV=?@(e6&s z`zbhlCUg+Jl&SV?G<0@QnFe?tf9V>+uhwstw!wajPJeIEuwoC*=gbjF5=z!7N#rMu zVo{{2RQj7yCPGD{bz&E-REC2SOSxG6XZPuogP&jY_hXO;hiU8`$gxyjkPZ(LB|IH? z@*oKgAL8f-5tVpZ;uZo#}1N zY&WG)%s~*jqH$7f0^U(fjX)pTd%ku`C}U>NjCoxka8NOGfMV#YNjF;nUs#Ud1}LwIDS z_UP99YL5)nj%5@_7(0k#GqvN}^Q#@3scnvg#&?q*)hYdKYLt)47fPIIjO$61(@Q41 zThYHeTYyjL$;_4G`69s81_4VoZ=P#Yoq7KKiix|kneco=y`xM@iWwQAhvUm-_Xxi|`*DCtR{!13ZJjUy51M-?wKu8?)znaxT^`%;M{ zXWf#tVI*n)^NO1pBS{-ZQd|2fOMT`dV6kpywx-5DHhf%>yggg+V=J?9Zl|6f$02^p z#32^VG-Jaj^J~UdhMIG&RUnu<;X2LJ*O*-IRwU0D8M$Es(i&qlur{HY+OgW3U+vf| zCW>}0>6?kUCDkh4E#o-nLCUp~n2G`qgCmJ=r1Ry33(fIiuH-@S0IySSR3>hxsn8Ga z2fAsuhEb*bT>C?cDu1YIpM<@su1~)^Cyph4ewJSU8w)SYQZ3cDmC5{ZHsdq)Z05Z& z%vmcR*2U(%Q_mvhsYF9K(Nd!o9z#`9|9vz6|L5o1n}y4HB!-gnVuABv z3>kLCiyp_^LxhtniZ+eZB0-N}nP7$BBEcmBN@o>qYN*Qulr5@tf(-&n$JAAVYXp?k zsOtoj8K^$NO#=G#u4MdW?oVmIY9i3R(+3Ey?KWrqD_d?a7VfJo2yycxEqZ%N&d+O` zJjrPocP2Y5K^*NUd8`60i|+ZUqH}g`0UJ+7T@`K?1sGDPX5Hj$N2T1HDcqNMb{}V> Yy!(d?74DalvHr>-SG3)6tI>1*1pvGS5dZ)H From f48c1d69773ad3867568dec8906ed6c38abea50e Mon Sep 17 00:00:00 2001 From: Chaitanya Date: Mon, 22 Apr 2024 15:50:35 +0530 Subject: [PATCH 5/5] improved the code --- practice/pig-latin/pig_latin.py | 47 ++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/practice/pig-latin/pig_latin.py b/practice/pig-latin/pig_latin.py index ade63c1..45f758d 100644 --- a/practice/pig-latin/pig_latin.py +++ b/practice/pig-latin/pig_latin.py @@ -1,18 +1,53 @@ def translate(text): - VOWELS = {"a", "e", "i", "o", "u"} - VOWELS_Y = {"a", "e", "i", "o", "u", "y"} - SPECIALS = {"xr", "yt"} + """ + Translate a text to Pig Latin. + + Pig Latin is a language game that children use to speak in code. + The rules to translate a word into Pig Latin are: + + - If a word begins with a vowel (a, e, i, o, u), append "ay" to the end of the word. + - If a word begins with a consonant, move it to the end of the word, and then append "ay". + - If a word starts with "xr" or "yt", treat it as if it starts with a vowel. + - If "y" comes after a consonant cluster, it makes a vowel sound (e.g., "rhythm" -> "ythmrhay"). + - If "u" follows a "q" that has been moved to the end of the word, it should also be moved (e.g., "quiet" -> "ietquay"). + + Args: + text (str): The text to be translated. + + Returns: + str: The translated text. + + Examples: + >>> translate("hello") + "ellohay" + >>> translate("apple") + "appleay" + """ + # Define the set of vowels and vowels including 'y' + vowels = {"a", "e", "i", "o", "u"} + vowels_y = {"a", "e", "i", "o", "u", "y"} + + # Define the set of special cases where the word starts with these two letters + specials = {"xr", "yt"} + + # Initialize the list to store the translated words piggyfied = [] + # Iterate over each word in the input text for word in text.split(): - if word[0] in VOWELS or word[0:2] in SPECIALS: + # If the word starts with a vowel or a special case, append "ay" and continue to the next word + if word[0] in vowels or word[0:2] in specials: piggyfied.append(word + "ay") continue + # If the word starts with a consonant, find the position of the first vowel for pos in range(1, len(word)): - if word[pos] in VOWELS_Y: + if word[pos] in vowels_y: + # If the vowel is 'u' and the previous letter is 'q', increment the position pos += 1 if word[pos] == 'u' and word[pos - 1] == "q" else 0 + # Move the consonant(s) to the end of the word, append "ay", and break the loop piggyfied.append(word[pos:] + word[:pos] + "ay") break - return " ".join(piggyfied) + # Join the translated words with spaces and return the result + return " ".join(piggyfied) \ No newline at end of file