Wednesday 29 May 2019

python - Add the trailing characters upto the first first occurrence of a vowel to the end of the word

I don't think the heading quite explained it sufficiently.



Basically I have a list containing all of the vowels and another list containing the characters that make up the word.



I need to take the list containing the word and take all of the characters up to the first vowel and add them onto the end in order.




What I can't wrap my head around is how to do it, I had two ideas:



for characters in word:
if(character != vowel):
vCount += 1
else:
break
break


for i in range(vCount):
print(i)
wList.append(wList.pop(i))


And another that was basically the same but every time it saw it wasn't a vowel it pop'd it out. The obvious issue I didn't see with these initially is that 'vowel' isn't just a singular entity, character doesn't equal a, pop, character doesn't equal e, pop, etc etc. Or in the case of vCount, it just got far longer than the actual length of wList.



Anyone have a thought on how to solve this?



EDIT: Sorry, that wasnt clear:




cat -> atc



bear -> earb

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...