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 )
    
« December 2026 »
Su Mo Tu We Th Fr Sa
12345
6789101112
13141516171819
20212223242526
2728293031
 

Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: