I’m trying to compress my code (least lines and characters challenge with a friend), and I’ve run into a problem.
outputWord = ""
def translate(inp):
output = []
words = inp.split()
for i in range(len(words)):
outputWord = ""
curWord = words[i]
if curWord[0] in ("a", "o", "e", "u"):
outputWord = curWord + "way"
else:
pos = curWord.rfind("a") # this is the problem.
outputword = curWord[pos:] + curWord[:pos] + "ay"
output.append(outputWord)
return(output)
output = translate(raw_input(""))
print(' '.join(output))
Here’s my code.
When I’m defining problem, I’m trying to find the first character that is a vowel, (not including y). But I’m not able to think of a way to do it in as little lines as possible. Basically, it searches for all vowels, and the smallest value is set to pos. That’s what I’m trying to do, but everything I’ve tried takes up over 10 lines.
I’ve tried using if statements, for loops, lists, variables, and rfind(). None have gotten a desirable result.
All of the existing questions of StackOverflow are for searching for one character, not five and to check which one has the smallest index.
Please don’t do it for me, just give me ideas or resources that can help. It’s an independent challenge and we are allowed to use StackOverflow.
aqwek_ is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.