I'm creating a car sales program and need to use a dictionary, I have a basic understanding of them. Would it be efficient to hold the car name as a string for the key, then store the relevant cars selling price in the values through a list? for example,
Audi1Price = 1000
Audi2Price = 1500
Cars = ["Audi": [Audi1Price, Audi2Price]]
Can this work? Is there a better usage for the dictionary?
Maybe there's a better way to work with the selling price as I'd like to print it out too, I'm unsure. Thanks
CodePudding user response:
Yes, that could work.
There is a problem in your example code, though: you used []
instead of {}
for the dictionary.
You need to do this:
Audi1Price = 1000
Audi2Price = 1500
Cars = {
"Audi": [Audi1Price,Audi2Price]
}