0

how do you change the order of characters in string?

I want to reverse letters in any given input

1st Jan 2020, 7:58 AM
Paapa Fahodzi
Paapa Fahodzi - avatar
6 Réponses
+ 4
original_string = "donatoe" #Easy way: new_string = original_string[::-1] #Hard way: new_string = "" i = len(new_string) - 1 while i != -1: new_string += original_string[i] i -= 1
1st Jan 2020, 9:24 AM
Seb TheS
Seb TheS - avatar
+ 1
Can you provide some examples? I'm not getting what you're asking for here.
1st Jan 2020, 8:06 AM
Ipang
+ 1
My way one = 'abcdefg' two = [] for i in one: two.append(i) print(''.join(two[::-1]))
1st Jan 2020, 9:32 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
Sound like you want a code for the extraterritorial challenge. You've been given some good pointers already. I suggest you review your lessons about iteration and have a look at these previous posts for your answer. Best if you do this yourself, else nothing is learnt
2nd Jan 2020, 12:52 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
thanks
2nd Jan 2020, 1:17 AM
Paapa Fahodzi
Paapa Fahodzi - avatar
0
for example say I want to reverse "good boy" to "doog yob"
2nd Jan 2020, 12:06 AM
Paapa Fahodzi
Paapa Fahodzi - avatar