Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (26.4k points)

Check the below example:

 input:  I live in New York

 output: York New in live I

P.S: I have utilized s[::- 1], this simply turns around the string, as kroY weN ni evil I, yet this isn't the ideal yield. I additionally attempted : 

However, this likewise stands wrong. Compassionately help me recorded as a hard copy of the code. 

1 Answer

0 votes
by (12.7k points)

You can utilize split to get the different words, opposite to reverse the rundown/list, lastly join to go along with them again to make the last string:

s = "This is New York"

# split first

a = s.split()

# reverse list

a.reverse()

# now join them

result = " ".join(a)

# print it

print(result)

Output:

'York New is This'

Wanna become a Python expert? Come and join the python certification course and get certified.

Related questions

0 votes
1 answer
asked Jul 18, 2019 in Java by Shubham (3.9k points)
0 votes
1 answer
asked Feb 19, 2021 in Python by laddulakshana (12.7k points)
0 votes
1 answer
asked Jan 2, 2021 in Python by laddulakshana (12.7k points)
0 votes
1 answer
asked Sep 23, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

29.3k questions

30.6k answers

501 comments

104k users

Browse Categories

...