+ 2

Help me to fix the problem ??

a = input().lower() for i in "aeiou": a = a.replace(i,i) print(a) You are given a string 'S'. Your task is to reverse the vowels in the string while keeping the consonants unchanged.

12th Aug 2021, 3:45 PM
Shahir
Shahir - avatar
32 Réponses
+ 10
Hi Shahir! Nice concept. Let's check I understood your question correctly. Input: Shahir Output: shihar Am I correct?
12th Aug 2021, 3:59 PM
Python Learner
Python Learner - avatar
+ 14
that is my basic try: inp = input().lower() vowels = "aeiou" vow_lst = [i for i in inp if i in vowels] for char in inp: print(vow_lst.pop(),end="") if char in vowels else print(char,end="") vow_lst containes a list of all occuring vowels in the sequence they appear. when printing, pop() is used which picks and removes always the last vowel of the vow_lst from the end of the list, so it is accessing them in reverse order.
12th Aug 2021, 5:40 PM
Lothar
Lothar - avatar
+ 6
one possible solution: a=input() av="" for i in a: if i in "aeiouAEIOU": av+=i b=""; c=0 for i in a: if i in "aeiouAEIOU": c+=1 b+=av[-c] else: b+=i print(b)
12th Aug 2021, 4:59 PM
Harshit Jawla
Harshit Jawla - avatar
+ 6
My solution a = input().lower() l = [] e = "" for i in a: if i in "aeiou": l.append(i) for i in a: if i in "aeiou": e += l.pop() else: e += i print(e)
12th Aug 2021, 5:03 PM
Python Learner
Python Learner - avatar
+ 5
a=input() b=list(a) g="" c=[] vovel="aeiou" for i in b: if i in vovel: c+=[a.index(i)] g=i+g a=a.replace(i,' ',1) for l,i in zip(g,c): b[int(i)]=l print(*b)
12th Aug 2021, 4:58 PM
Amir
Amir - avatar
+ 5
This is my try: https://code.sololearn.com/c5KsxHR3iVgj Explanation: First, it takes all the vowels in a list from the string in a reverse way with list comprehension, and then again iterates the string and adds to a list if it's a non-vowel otherwise if it's a vowel it takes the value from the reversed vowel list and adds it and at last print the list as a string.
12th Aug 2021, 5:43 PM
The future is now thanks to science
The future is now thanks to science - avatar
+ 4
Shahir , replacing "i" with "i" does not change anything. can you please make an output sample for the input sample: "klaxiuaaz" ?
12th Aug 2021, 4:06 PM
Lothar
Lothar - avatar
+ 4
Here's a one-liner possibility: print("".join(map(lambda x: b.pop() if x in "aeiou" else x, (a := input().lower()) + str(b := [x for x in a if x in "aeiou"]) * 0))) # Hope this helps # Happy coding!
13th Aug 2021, 7:12 AM
Calvin Thomas
Calvin Thomas - avatar
+ 4
Sunday Olorunfemi , as i understand, the vovels will be handled like: _a_iia_eau_oooo # <<<< input _o_ooo_uae_aiia # <<<< output the underscore can be seen as any other letter or number
13th Aug 2021, 3:29 PM
Lothar
Lothar - avatar
+ 3
Yes python Learner that's how the output should
12th Aug 2021, 4:24 PM
Shahir
Shahir - avatar
+ 3
Harshit Jawla I paste my code, but Not fully pasted
12th Aug 2021, 5:28 PM
Amir
Amir - avatar
+ 3
s = list("hello heres my solution") i,j = 0,len(s)-1 while True: while i<len(s)-1 and s[i] not in "aeiou": i += 1 while j>=0 and s[j] not in "aeiou": j -= 1 if i >= j: break s[i],s[j] = s[j],s[i] i, j = i+1, j-1 print("".join(s))
12th Aug 2021, 5:38 PM
Giorgos
+ 3
Could you please explain me your code once
13th Aug 2021, 7:22 AM
Shahir
Shahir - avatar
+ 3
Calvin Thomas your oneliner code did not work.
13th Aug 2021, 1:43 PM
Sunday Olorunfemi
+ 2
Use two variables i,j in a loop, let i go forwards from 0 and j go backwards from the end. Move each one until you meet a vowel character, then swap those characters, and repeat. Stop when i,j pass each other. Since its an exercise, i will just let the implementation details for you to figure out
12th Aug 2021, 4:20 PM
Giorgos
+ 2
Harshit Jawla There is no v variable in my code. c and g I walk on the input str and add its vowels to the variable g and add the index to variable C. Line 6 indentation is because we're in the for loop.
12th Aug 2021, 5:16 PM
Amir
Amir - avatar
+ 2
Amir see I mentioned that for your previous code, not your edited one
12th Aug 2021, 5:26 PM
Harshit Jawla
Harshit Jawla - avatar
+ 2
Lew!S✨ perfect 🤘
12th Aug 2021, 5:43 PM
Harshit Jawla
Harshit Jawla - avatar
+ 2
yes
13th Aug 2021, 12:05 PM
Shahir
Shahir - avatar
+ 2
Shahir Apart from certain minor differences, the explanation pretty much simplifies to Lothar's explanation given above.
13th Aug 2021, 12:11 PM
Calvin Thomas
Calvin Thomas - avatar