Skip to content
Advertisement

Usage of a dictionary, Right or wrong?

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,

JavaScript

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

Advertisement

Answer

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:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement