Python Assignments Python ADT Rev 1.0
Python Assignments Python ADT Rev 1.0
a. Read the text, tokenize and store all tokens in a python list. (Tokens can be
separated with space, tab, comma, semicolon).
c. Search for those tokens which are of even length and display them.
f. Update the output file with the contents of the modified list.
(You need to refer the python file handling functions too to solve this question)
2) Write a function is_member() that takes a value (i.e. a number, string, etc) x and a list of
values a, and returns True if x is a member of a, False otherwise. (Note that this is
exactly what the in operator does.)
3) Define a function overlapping() that takes two lists and returns True if they have at least
one member in common, False otherwise. You may use your is_member() function, or
the in operator, but for the sake of the exercise, you should (also) write it using two
nested for-loops.
4) Write a program that maps a list of words into a list of integers representing the lengths
of the corresponding words.
5) Write a function find_longest_word() that takes a list of words and returns the length of
the longest one.
6) Write a version of a palindrome recognizer that also accepts phrase palindromes such
as "Go hang a salami I'm a lasagna hog.", "Was it a rat I saw?", "Step on no pets", "Sit
on a potato pan, Otis", "Lisa Bonet ate no basil", "Satan, oscillate my metallic sonatas",
"I roamed under it as a tired nude Maori", "Rise to vote sir", or the exclamation "Dammit,
I'm mad!". Note that punctuation, capitalization, and spacing are usually ignored.
7) Write a function char_freq() that takes a string and builds a frequency listing of the
characters contained in it. Represent the frequency listing as a Python dictionary. Try it
with something like char_freq("abbabcbdbabdbdbabababcbcbab").
key = {'a':'n', 'b':'o', 'c':'p', 'd':'q', 'e':'r', 'f':'s', 'g':'t', 'h':'u', 'i':'v', 'j':'w', 'k':'x', 'l':'y', 'm':'z', 'n':'a',
'o':'b', 'p':'c', 'q':'d', 'r':'e', 's':'f', 't':'g', 'u':'h', 'v':'i', 'w':'j', 'x':'k', 'y':'l', 'z':'m', 'A':'N', 'B':'O',
'C':'P', 'D':'Q', 'E':'R', 'F':'S', 'G':'T', 'H':'U', 'I':'V', 'J':'W', 'K':'X', 'L':'Y', 'M':'Z', 'N':'A',
'O':'B', 'P':'C', 'Q':'D', 'R':'E', 'S':'F', 'T':'G', 'U':'H', 'V':'I', 'W':'J', 'X':'K', 'Y':'L', 'Z':'M'}
Note that since English has 26 characters, your ROT-13 program will be able to both
encode and decode texts written in English.
9) Take an input file name and an output file name from command line where the input file
has some text. Then do the following:
a) Read the text, tokenize and store all tokens in a suitable python data type, along
with their frequency of occurrence.
c) Update the output file with tokens and their frequency (one record in one line)
(You need to refer the python file handling functions too to solve this question)