Assignment 22 — function implementation that manipulate lists
Due before class Friday, March 30
Module quad.py
- Defines four functions for cleaning up lists of strings. Program quadriga.py performs simple testing of quad.py.
- Observation: none of the function implementations require nested
for
-loops.
Suppose the following definitions are in effect below
test1 = ['AbCdE', 'ABCDE', '!"#\'x$&)|}~', '- x -_', 'AAcc', ' ', 'x\n']
test2 = ['\tx X']
test3 = []
test4 = ['a', 'B', 'r', 'A', 'c', 'a', 'D', 'a', 'B', 'r', 'a']
Function lower( strings )
- Returns a new list whose elements are lower case versions of those in
strings
.
- Given the above definitions of
test1
,test2
,test3
, andtest4
, the following is the expected invocation results forlower()
.
lower( test1 ) = ['abcde', 'abcde', '!"#\'x$&)|}~', '- x -_', 'aacc', ' ', 'x\n']
lower( test2 ) = ['\tx x']
lower( test3 ) = []
lower( test4 ) = ['a', 'b', 'r', 'a', 'c', 'a', 'd', 'a', 'b', 'r', 'a']
Function unique( strings )
- Returns a new version of
strings
without any duplicate values.
- Given the above definitions of
test1
,test2
,test3
, andtest4
, the following is the expected invocation results forunique()
.
unique( test1 ) = ['AbCdE', 'ABCDE', '!"#\'x$&)|}~', '- x -_', 'AAcc', ' ', 'x\n']
unique( test2 ) = ['\tx X']
unique( test3 ) = []
unique( test4 ) = ['a', 'B', 'r', 'A', 'c', 'D']
Function strip( strings )
- Returns a new list whose elements correspond to the elements in
strings
with leading and trailing extraneous characters (punctuation or whitespace) removed.
- Given the above definitions of
test1
,test2
,test3
, andtest4
, the following is the expected invocation results forstrip()
.
strip( test1 ) = ['AbCdE', 'ABCDE', 'x', 'x', 'AAcc', '', 'x']
strip( test2 ) = ['x X']
strip( test3 ) = []
strip( test4 ) = ['a', 'B', 'r', 'A', 'c', 'a', 'D', 'a', 'B', 'r', 'a']
Function canonical( strings )
- Returns a new list without duplicates whose elements are lower case versions of those in
strings
with leading and trailing extraneous characters removed.
- Given the above definitions of
test1
,test2
,test3
, andtest4
, the following is the expected invocation results forcanonical()
.
canonical( test1 ) = ['abcde', 'x', 'aacc', '']
canonical( test2 ) = ['x x']
canonical( test3 ) = []
canonical( test4 ) = ['a', 'b', 'r', 'c', 'd']
Warning: fopen(/l/cs1112/public_html/defs/htm/181-trailer): Failed to open stream: No such file or directory in /l/cs1112/public_html/defs/php/read.php on line 5
Unable to open file!