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 does a for loop work in Python?


Implement a fibonacci function which calculates the nth number of the fibonacci sequence.


Write a function that takes a list of numbers as input, and outputs the average of the numbers. The function should catch any errors.


What is the outcome of the following code? print(2*[3,4,5])