How do I turn a list of lists of words into a sentence string?

前端 未结 4 1558
南旧
南旧 2021-02-07 00:17

I have this list

[[\'obytay\'], [\'ikeslay\'], [\'ishay\'], [\'artway\']]

where I need it to look like

obytay ikeslay ishay ar         


        
4条回答
  •  野性不改
    2021-02-07 00:51

    def pig_latin(text):
      say = ""
      x=[]
    
      # Separate the text into words
      words = text.split()
    
      for word in words:
        # Create the pig latin word and add it to the list
        x.append(word[1:]+word[0]+'ay')
    
      for eachword in x:
        say += eachword+' '
        # Turn the list back into a phrase
      return say
            
    print(pig_latin("hello how are you")) # Should be "ellohay owhay reaay ouyay"
    
    print(pig_latin("programming in python is fun")) # Should be "rogrammingpay niay ythonpay siay unfay"
    

提交回复
热议问题