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 ▸

Using the shared code editor, write a recursive function for calculating a factorial of an input parameter.


Write a program that computes the sum of all numbers up to a input number n


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


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