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 ▸

Which four data types are used in Python? Can you give an example of each?


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


Make a program that asks the user for a series of numbers until they either want to output the average or quit the program.


How do you write code to implement a recursive fibonacci algorithm?