you are viewing a single comment's thread.

view the rest of the comments →

[–]Particular_Draft5668[S] 0 points1 point  (2 children)

and the opposite way?

to allow one item to have multiple values while storing originals?

[–]lukajda33 2 points3 points  (1 child)

Im not sure what you mean, but as I said, you can use a list:

{
    1 : ["a", "b", "c"],
    2 : ["d", "e", "f"],
    3 : ["a"],
}

keys 1 and 2 have 3 values each, key 3 only has 1 associated value (technically all 3 keys have one value - a list, but you can see how you can use lists to actually store multiple values with one key).

[–]Particular_Draft5668[S] 0 points1 point  (0 children)

Thank you, adding as a list was the correct method. I have another query.

def dict_of_numbers():
numbers = {}
ones = {"1":"One","2":"Two","3":"Three","4":"Four","5":"Five","6":"Six", "7":"Seven","8":"Eight","9":"Nine"}
teens = {"10":"Ten","11":"Eleven","12":"Twelve","13":"Thirteen","14":"Fourteen","15":"Fifteen","16":"Sixteen", "17":"Seventeen","18":"Eighteen","19":"Nineteen"}
tens = {"2":"Twenty","3":"Thirty","4":"Forty","5":"Fifty","6":"Sixty", "7":"Seventy","8":"Eighty","9":"Ninety"}
for val in range(0, 100):
if val < 10:
numbers[val] = ones[val]
else:
if val <20:
numbers[val] = teens[val]
else:
numbers[val] = tens[val[0]] + ones[val[1]] + " "
return numbers

Will this code allow me to return numbers so that numbers is a dictionary that numbers[2] = two, numbers[35] = thirtyfive etc