import anydbm cityDB = anydbm.open("city.dbm", 'r') timeDB = anydbm.open("time.dbm", 'r') flights = cityDB.keys() print "Arrivals" for flight in flights: print ("Flight %s arrives from %s at %s" % (flight, cityDB[flight], timeDB[flight])) cityDB.close() timeDB.close()