Reverse an input using tuples Python -


i want able write function reverse phrase such 'hello world' 'world hello'. far can to:

def reverser():     print('please input phrase')     inputphrase=input()     if ' ' in inputphrase: 

after i'm assuming need slice string , slice gets stored in tuple, , @ end variables print out.

it stored in list, not tuple. here's how in 2 lines:

my_input = input('your phrase: ') print(*reversed(my_input.split()))  # python 3 

or

print ' '.join(reversed(a.split()))  # python 2 

so function be:

func = lambda x: reversed(x.split()) 

which return list of reversed words phrase if called follows:

arg = input('enter phrase :') splitted = func(arg)  print(*splitted)  # or in python 2: print ' '.join(splitted) 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -