+ 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.
32 Respuestas
+ 10
Hi Shahir!
Nice concept.
Let's check I understood your question correctly.
Input: Shahir
Output: shihar
Am I correct?
+ 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.
+ 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)
+ 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)
+ 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)
+ 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.
+ 4
Shahir ,
replacing "i" with "i" does not change anything.
can you please make an output sample for the input sample: "klaxiuaaz" ?
+ 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!
+ 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
+ 3
Yes python Learner that's how the output should
+ 3
Harshit Jawla I paste my code, but Not fully pasted
+ 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))
+ 3
Could you please explain me your code once
+ 3
Calvin Thomas your oneliner code did not work.
+ 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
+ 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.
+ 2
Amir see I mentioned that for your previous code, not your edited one
+ 2
Lew!S✨ perfect 🤘
+ 2
yes