# List/Dictionary Tiz/Quest Answers # ------------------------------------------------- # 1. def Properties(filename): try: f=open(filename,'rU') lines=f.read().split('\n') f.close() except: print 'Cannot open '+filename return {} answer={} for line in lines: words=line.split('=') if len(words)==2: answer[words[0]]=words[1] return answer # -------------------------------------------------- # 2. def PropSum(list_of_filenames): while True: look_for=raw_input('Which property to sum (or nothing to quit): ') look_for=look_for.strip() if look_for=='': return prop_sum=0 for fname in list_of_filenames: dct=Properties(fname) if look_for in dct: if dct[look_for].isdigit(): prop_sum+=int(dct[look_for]) print 'Total %s = %d\n' % (look_for,prop_sum) # ------------------------------------------------- # 3. def Interleave(A,B): answer=[] for i in range(max(len(A),len(B))): if imode_dups: the_mode=anumber mode_dups=L.count(anumber) return the_mode