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 ▸

Write a short program to print all the even numbers 1 to 100


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


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


Write a Python script to take a product name as input and then automatically google search reviews for it and open the top 3 search results in different tabs