0
Help!!!!!
def reverse_words(text): a = text.split() for i in a: b = i[::-1] return "".join(b) I want to have not only one word but all of them! expectation: isht si ecni < Is reversed result in my end: isht
14 Antworten
+ 2
Here's a little 1 liner.
print(' '.join(map(lambda x: x[::-1], input().split())))
or this if you prefer unpacking
print(*map(lambda x: x[::-1], input().split()))
+ 2
Ailana i think you want the reverse_word function but if you don't
print(input()[::-1])
the most easiest
+ 1
text = (input() or "this is nice").split(" ")
def reverse_words(text):
a = text.split()
for i in a:
b = i[::-1]
return "".join(b)
print(*[reverse_words(i) for i in text])
+ 1
this should work
+ 1
A shorter version
0
def reverse_words(text):
a = text.split()
c= []
for i in a:
b = i[::-1]
c.append(b)
return " ".join(c[::-1])
print(reverse_words('hello world'))
0
inp = input()
def reverse_words(words):
reversed = words[::-1]
return reversed
word = reverse_words(inp)
print(word)
0
Append b in every iteration to another list and use that list to join
0
Ailana be careful: if you use a variable "b" only in the loop it will be overwritten every time a cycle of the loop is executed, so finally "b" will be the last value of the loop.
If you want to find the errors I suggest you to print every important passage:
https://code.sololearn.com/cOjZpT90na24/?ref=app
So, you have to define a variable "c" out of the loop to have a final value with all the words:
https://code.sololearn.com/cKb5Y1uWCg62/?ref=app
But there are no reason to do it to reach the result:
https://code.sololearn.com/c13FfoO6Dm2F/?ref=app
I hope this helps you!
Bye!
0
Evandro Simorangkir i think your input statement is "this is nice" and second of all you cant give yourself input sololearn will give it
0
inp = 'this is nice'
words = inp.split()
for n in range(len(words)) :
words[n]=words[n][::-1]
print (' '.join(words[x] for x in range(len(words))))
0
Eashan Morajkar just change into "inp=input()" for user typing input. Simple
0
def reverse_words(text):
a = text.split()
result = []
for i in a:
result.append(i[::-1]
)
return " ".join(result)
print(reverse_words("this Works!"))
Here i'm appending the reversed Word to an empty list. :D
- 1
inp = input()
def reverse_words(words):
reversed = words[::-1]
return reversed
print(reverse_words(inp))