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 ▸

What is the difference between a cycle "if" and "while"?


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


Write a basic program to output the lowest of 3 input numbers. (You may omit error checks on your inputs)


Write a function that checks whether a number is prime or not.