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 to compute the factorial of a number.


How would you write a while loop to print all even numbers from 1-10?


When do we use a for-loop and when a while-loop?


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