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)
#2
If I understand correctly 'the translation' means that first character is moved to an end and 'ay' is added to all words which are longer than 1 letter.

One possibility to create translate function and then use it on all words in sentence.

def translate(word): 
    if len(word) == 1: 
        return word 
    else: 
        return f'{word[1:]}{word[0].lower()}ay'
Then just:

>>> sentence = 'Climb a tree'                                                                                                                                                
>>> ' '.join([translate(word) for word in sentence.split()])                                                                                                                 
'limbcay a reetay'
This must be further developed. It will not work as expected with the punctuation at the end of sentence and there is no rules for capitalisation of words.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


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

Possibly Related Threads…
Thread Author Replies Views Last Post
  (python) Can i get some help fixing a English to Morse translator? Pls AlexPython 8 3,158 Dec-03-2024, 10:21 AM
Last Post: skylartyler
  non-latin characters in console from clipboard Johanson 3 1,556 Oct-26-2023, 10:10 PM
Last Post: deanhystad
  Pulling Specifics Words/Numbers from String bigpapa 2 1,584 May-01-2023, 07:22 PM
Last Post: bigpapa
  "If Len(Word) == 0" Code Block in Pig Latin Program new_coder_231013 3 3,090 Jan-02-2022, 06:03 PM
Last Post: deanhystad
  Extract a string between 2 words from a text file OscarBoots 2 2,723 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 3,953 Aug-11-2021, 03:45 PM
Last Post: jamesaarr
  i want to write symbole as varibales in python to make translator rachidel07 9 4,993 Feb-03-2021, 09:57 PM
Last Post: nilamo
  Replacing a words' letters in a string cananb 2 4,643 Dec-01-2020, 06:33 PM
Last Post: perfringo
  Trying to find first 2 letter word in a list of words Oldman45 7 5,866 Aug-11-2020, 08:59 AM
Last Post: Oldman45
  Pressing non-latin characters? Murlog 0 1,917 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