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

27th May 2021, 12:30 AM
Ailana
Ailana - avatar
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()))
27th May 2021, 11:34 PM
ChaoticDawg
ChaoticDawg - avatar
+ 2
Ailana i think you want the reverse_word function but if you don't print(input()[::-1]) the most easiest
28th May 2021, 7:30 AM
Eashan Morajkar
Eashan Morajkar - avatar
+ 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])
27th May 2021, 3:36 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
this should work
27th May 2021, 4:21 AM
Eashan Morajkar
Eashan Morajkar - avatar
+ 1
A shorter version
27th May 2021, 4:21 AM
Eashan Morajkar
Eashan Morajkar - avatar
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'))
27th May 2021, 12:41 AM
Alaa Aldeen Shammr
Alaa Aldeen Shammr - avatar
0
inp = input() def reverse_words(words): reversed = words[::-1] return reversed word = reverse_words(inp) print(word)
27th May 2021, 4:20 AM
Eashan Morajkar
Eashan Morajkar - avatar
0
Append b in every iteration to another list and use that list to join
27th May 2021, 1:38 PM
RuntimeERROR
RuntimeERROR - avatar
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!
28th May 2021, 11:56 AM
Raffaele Bisogno
Raffaele Bisogno - avatar
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
28th May 2021, 3:29 PM
Eashan Morajkar
Eashan Morajkar - avatar
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))))
28th May 2021, 3:37 PM
Evandro Simorangkir
Evandro Simorangkir - avatar
0
Eashan Morajkar just change into "inp=input()" for user typing input. Simple
28th May 2021, 3:43 PM
Evandro Simorangkir
Evandro Simorangkir - avatar
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
28th May 2021, 9:20 PM
6hpxq9
6hpxq9 - avatar
- 1
inp = input() def reverse_words(words): reversed = words[::-1] return reversed print(reverse_words(inp))
27th May 2021, 4:21 AM
Eashan Morajkar
Eashan Morajkar - avatar