Problem 1 uniq = len(set(lista)) smalls = [w for w in lista if len(w) < 6] most = max([lista.count(x) for x in lista]) Part D: occs = [(w,lista.count(w)) for w in set(lista)] phase1 = sorted(occs,key=itemgetter(0)) # can leave out key= phase2 = sorted(phase1,key=itemgetter(1),reverse=True) ordered = [t[0] for t in phase2] **************************** Problem 2 A B C D: def get_totals(rolld) d = {} for roll in rolld: s = roll[0] + roll[1] d[s] = d.get(s,0) + rolld[roll] return d **************************** Problem 3 rtotal = sum([c[2] for c in contribs if c[3] == 'R']) heavies = [c[0] for c in contribs if c[2] > 15000000] def small_donors(contribs,donors): lst = [] for tuple in contribs: pol = tuple[0] smalls = [x for x in donors[pol] if x[2] < 1000] lst.append( (pol,len(smalls)) ) return lst **************************** Problem 4 def artists(filename): f = open(filename) d = {} for line in f: parts = line.strip().split(":") song = parts[0].strip() artist = parts[1].strip() if artist not in d: d[artist] = [] d[artist].append(song) f.close() return d