MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / pig_latin

Function pig_latin

strings/pig_latin.py:1–38  ·  view source on GitHub ↗

Compute the piglatin of a given string. https://en.wikipedia.org/wiki/Pig_Latin Usage examples: >>> pig_latin("pig") 'igpay' >>> pig_latin("latin") 'atinlay' >>> pig_latin("banana") 'ananabay' >>> pig_latin("friends") 'iendsfray' >>> pig_lat

(word: str)

Source from the content-addressed store, hash-verified

1def pig_latin(word: str) -> str:
2 """Compute the piglatin of a given string.
3
4 https://en.wikipedia.org/wiki/Pig_Latin
5
6 Usage examples:
7 >>> pig_latin("pig")
8 'igpay'
9 >>> pig_latin("latin")
10 'atinlay'
11 >>> pig_latin("banana")
12 'ananabay'
13 >>> pig_latin("friends")
14 'iendsfray'
15 >>> pig_latin("smile")
16 'ilesmay'
17 >>> pig_latin("string")
18 'ingstray'
19 >>> pig_latin("eat")
20 'eatway'
21 >>> pig_latin("omelet")
22 'omeletway'
23 >>> pig_latin("are")
24 'areway'
25 >>> pig_latin(" ")
26 ''
27 >>> pig_latin(None)
28 ''
29 """
30 if not (word or "").strip():
31 return ""
32 word = word.lower()
33 if word[0] in "aeiou":
34 return f"{word}way"
35 for i, char in enumerate(word): # noqa: B007
36 if char in "aeiou":
37 break
38 return f"{word[i:]}{word[:i]}ay"
39
40
41if __name__ == "__main__":

Callers 1

pig_latin.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected