0

How to reverse a name in python?

To reverse a "solo learn" to "learn solo" Without using array

23rd May 2021, 7:15 AM
Goku
Goku - avatar
6 odpowiedzi
+ 6
s=input().split() print(' '.join(s[::-1]))
23rd May 2021, 7:19 AM
sarada lakshmi
sarada lakshmi - avatar
+ 3
Sadra Shakouri 🇮🇷 There is no reverse attribute in str object.
23rd May 2021, 8:20 AM
A͢J
A͢J - avatar
23rd May 2021, 8:35 AM
Sadra Shakouri
Sadra Shakouri - avatar
+ 2
23rd May 2021, 7:30 AM
Goku
Goku - avatar
+ 2
""" mmhh... OP said in description: << to reverse a "solo learn" to "learn solo" Without using array >> but split return a list (wich are python array in a sense) ^^ """ s = " " + input() r = "" w = "" for c in s[::-1]: if c != " ": w = c + w continue if r: r += " " if w: r += w w = "" print(r)
23rd May 2021, 2:55 PM
visph
visph - avatar
+ 1
Sadra Shakouri 🇮🇷 I mess up every time I don't take the time to verify, so I know how you feel. Good on you for acknowledging your mistake
23rd May 2021, 9:37 AM
Rik Wittkopp
Rik Wittkopp - avatar