Search code examples
pythonfunctionnested-loops

How to select and remove all the first consonants of a word and place them at the end of the word in python?


I want to remove all the first consonants of a word and place them at the end of the word

input -> "step down"

output -> "epst ownd"

this is my code so far:

def lang(text):
    alist=text.split() 
    vokaler="äåöaeiouÄÅÖAEIOU"
    retText=""
    for word in alist:
        nytext=""
        nytext_b=""
        n=0
        for tkn in word:
            if not tkn in vokaler:
                nytext+=tkn
                n+=1
            else:    
                for rest in word[n:]:
                    nytext_b+=rest
                    retText=nytext_b+nytext+"all"+" "

    return retText

print(lang("step down"))

Solution

  • If you want to put every letter of the string to end then you can use following code:

      a="step down"
      l=a.split()
      print l
      data1=""
      for x in l:
         data=x[1:]+x[0:1]
         data1=data1+data
    
         data1=data1+" "
      print data1
    

    output:

      teps ownd