Personal tools
You are here: Home → Comp 171 Scripting Practicum → Course Materials → Python Materials → Python Programs → Reverse Words In A String
Document Actions

Reverse Words In A String

by Dr. William L. Honig — last modified 2012-02-10 11:10 PM

A function to reverse the words in a string (using a temporary list)

Click here to get the file

Size 1 kB - File type text/python-source

File contents

# 
#Comp 171 Standard Python Script Header 
#Assignment name: Help with Stringing Along
#LUC id and Name: whonig@luc.edu Dr. William L. Honig 
#Date 12 Feb 12 
# 
#Reverse words in a string by converting to a list
# 
#Questions: None
#
def reverseMe(aString):
    aList = aString.split()
    aList.reverse()
    bString = " ".join(aList)
    return( bString )
    
« October 2027
Su Mo Tu We Th Fr Sa
12
3456789
10111213141516
17181920212223
24252627282930
31
 

Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: