Skip to content

Instantly share code, notes, and snippets.

@jgarciabu
Created August 9, 2017 19:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgarciabu/3331667a40823105386f0e06b98b056a to your computer and use it in GitHub Desktop.
Save jgarciabu/3331667a40823105386f0e06b98b056a to your computer and use it in GitHub Desktop.
Ex 15 List Reverse
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Write a program (using functions!) that asks the user for a long string
containing multiple words. Print back to the user the same string, except with
the words in backwards order. For example, say I type the string:
My name is Michele
Then I would see the string:
Michele is name My
shown back to me.
@author: Jeff Garcia
"""
def reverse_input(phrase):
result = phrase.split(" ")
newlist = reversed(result)
finallist = " ".join(newlist)
return finallist
print(reverse_input(input("Enter a phrase and I'll recite it backwards:")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment