# Create a dictionary using as the source data a tuple for # the key set and a corresponding list for the value set # Allow the user to enter the key/value pairs # Initialise empty tuple and list key_source=() val_source=[] # Loop over user input cont="yes" while cont == "yes": key=raw_input("Enter the dictionary key: ") if key in key_source: print "*** Key \"%s\" is already in the dictionary ***" % key continue value=raw_input("Enter the corresponding value: ") key_source = key_source + (key,) val_source.append(value) cont=raw_input("Do you wish to enter another key/value pair? (yes/no) ") # Set up the sources for the keys (tuple) and the values # (list) print print "Keys\t:",key_source print "Values\t:",val_source # Set up the dictionary # Brute force way - iterate over keys and values d=dict() for i in range(len(key_source)): d[key_source[i]] = val_source[i] # Echo the dictionary contents to screen print print "Dictionary set up: ",d # Echo the entries print for name in d.keys(): print "%s\t: %s" % (name,d[name])