So I want to make a method that creates a dictionary based on input. 3 different ones, a dictionary with keys 0-9 for decimal, keys 0-7 for octal and keys 0-F for hexadecimal. I use a string with items 0-F as a way of creating the keys and depending on which file is used for the creation (different ones for different number systems) it'll create the dictionary with the appropriate keys.
My question is, for the octal and decimal files, how do I use dictionary comprehension to to limit the amount of keys to be created? So fileDec will stop at key 9 and fileOct will stop at key 7. Right now it creates a dictionary with all 16 keys regardless.
def create_dictionary(file):
if file == fileDec:
sortBins = {item : [] for item in dictionIndexes}
return sortBins
elif file == fileOct:
print("Oct")
elif file == fileHex:
print("Hex")
mainBin = []
dictionIndexes = "0123456789ABCDEF"
sortBins = {}
fileDec = open("Number Lists/random_numbers10.txt")
fileDec.close()
fileOct = open("Number Lists/random_numbers4.txt")
fileOct.close()
fileHex = open("Number Lists/random_numbers3.txt")
fileHex.close()
sortBins = create_dictionary(fileDec)
for item in dictionIndexes:
print(item, sortBins[item])
print(len(dictionIndexes))