2 odpowiedzi
+ 9
Dictionaries are a lot more different than lists in python
The former is like switch statement in java and the latter is like arrays in java
Dictionary contains elements in the form of 'key':'value' pairs, while lists contains only single elements
Examples:
dict = {1: "one"; 2: "two", 3: "three"}
# a dictionary
li = [1,2,3]
# a list
+ 2
Both are container for a sequence of objects.
Lists are orderable, dictionaries are not.
Lists use numeric indexes from 0 by step 1 (0,1,2...), dictionaries use keys.
Context will determine wich kind of structure is best suited for each cases (but is not limited to these two ones: you could also look at 'tuples' and 'sets' for example, in the built-in sequence data structures ^^)