Q1: def prepend(x,s,n): return n*s + x a = 'abc' print prepend(a,'88',3) # prints '888888abc' Q2: class textfile: ntfiles = 0 # count of number of textfile objects def __init__(self,fname): textfile.ntfiles += 1 self.myrank = textfile.ntfiles self.name = fname # name self.fh = open(fname) # handle for the file self.lines = self.fh.readlines() self.nlines = len(self.lines) # number of lines self.nwords = 0 # number of words # omitting wordcount(), grep() for brevity # create test files x and y f = open('x','w') f.write('abc\nde\n') f = open('y','w') f.write('12\n888\n') a = textfile('x') b = textfile('y') print a.myrank # prints 1 print b.myrank # prints 2 Q3: def uniq(x): tmp = [] for xelt in x: if not xelt in tmp: tmp.append(xelt) return tmp u = [5,12,13,12,8] print uniq(u) Q4: class ulist(list): def __init__(self,x): self.x = uniq(x) list.__init__(self) def __add__(self,y): tmp = self.x + y return ulist(tmp) u = [5,12,13,12,8] u1 = ulist(u) v1 = u1 + [2,1,8,8] print v1.x