1. class diter: def __init__(self,d): self.d = d self.kys = d.keys() self.kynum = 0 def __iter__(self): return self def next(self): if self.kynum == len(self.d): raise StopIteration self.kynum += 1 return self.d[self.kys[self.kynum-1]] dt = diter({'a':5, 'b':12, 'c':13}) for delt in dt: print delt 2. from Queue import Queue import thread class glbls: Q = Queue() numThreads = 2 top = None Lock = thread.allocate_lock() sum = 0 def dowork(tnum): sum = 0 while True: try: i = glbls.Q.get(block=False) except: break sum += i glbls.Lock.acquire() glbls.numThreads -= 1 glbls.sum += sum glbls.Lock.release() glbls.top = int(raw_input('enter top: ')) for i in range(glbls.top+1): glbls.Q.put(i) thread.start_new_thread(dowork,(1,)) thread.start_new_thread(dowork,(2,)) while glbls.numThreads > 0: pass print glbls.sum