When to use a dectionary or a list

Lists retain order while dictionaries do not, hence time ordered data should only be used with lists. Dictionaries associate unique hashable keys with values, membership tests are also much faster with dictionaries (foo in bar). Lists allow for arithmetic operations much more readily than lists do (sum(), avg())

ML

Related Python Mentoring answers

All answers ▸

How would you loop over every key and value in a python dictionary?


Create an rock, paper, scissors game. The user should input one option, and the computer should play randomly.


Explain why creating a list of several instances of one element using something like my_list = [a] * 5 can result in strange behaviour


Create a program that checks for syntactical errors in an email address.