Python Forum
I want to filter out words with one letter in a string (pig latin translator)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I want to filter out words with one letter in a string (pig latin translator)
#1
How to create a function to ignore words with one letter in a string? I am trying to make a pig latin translator that can translate sentences but leaves words like "a" be. I've tried what I listed below, and get no errors, but it still adds "ay" on the end of one letter words. Please let me know what I'm doing wrong!

def piglatin(sentence):

    while len(sentence.split(' ')) > 1:
        return ' '.join(map(
            lambda str: str + 'ay' if str[0] in 'aeiou' else str[1:] + str[0] + 'ay',
            sentence.split(' ')
            )).capitalize()
        if len(sentence.split()) < 1:
            break
I'm also not sure if break should go at the end of loop.
For more explanation, this is what my program is doing now:
input: climb a tree
output: Limbcay aay reetay
What I want it do do:
output: Limbcay a reetay
Reply


Messages In This Thread
I want to filter out words with one letter in a string (pig latin translator) - by po0te - Jan-08-2020, 07:29 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  non-latin characters in console from clipboard Johanson 3 713 Oct-26-2023, 10:10 PM
Last Post: deanhystad
  Pulling Specifics Words/Numbers from String bigpapa 2 775 May-01-2023, 07:22 PM
Last Post: bigpapa
  (python) Can i get some help fixing a English to Morse translator? Pls AlexPython 7 1,621 Sep-12-2022, 02:55 AM
Last Post: AlexPython
  "If Len(Word) == 0" Code Block in Pig Latin Program new_coder_231013 3 2,084 Jan-02-2022, 06:03 PM
Last Post: deanhystad
  Extract a string between 2 words from a text file OscarBoots 2 1,885 Nov-02-2021, 08:50 AM
Last Post: ibreeden
  Generate a string of words for multiple lists of words in txt files in order. AnicraftPlayz 2 2,826 Aug-11-2021, 03:45 PM
Last Post: jamesaarr
  i want to write symbole as varibales in python to make translator rachidel07 9 3,534 Feb-03-2021, 09:57 PM
Last Post: nilamo
  Replacing a words' letters in a string cananb 2 3,476 Dec-01-2020, 06:33 PM
Last Post: perfringo
  Trying to find first 2 letter word in a list of words Oldman45 7 3,775 Aug-11-2020, 08:59 AM
Last Post: Oldman45
  Pressing non-latin characters? Murlog 0 1,539 Jul-25-2020, 03:10 PM
Last Post: Murlog

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020