03 Data Structures Flashcards
What kinds of data structures did we learn of?
- sequence types
- unordered collections
- mapping types
What are sequence types of data structures?
It’s an ordered list of values where the position/index of the values is used to access them.
ie: list, tuple, string, range
What are unordered collections?
unordered set of unique elements.
ie: set
What are mapping types of data structures?
It’s a group of key-value-pairs where unique keys are used to access their values.
ie: dictionary
What is the difference between a list and a tuple?
A list is mutable (can be changed), a tuple is immutable (can’t be changed).
(everytime a tuple is changed a new tuple with the same name is created and the old one gets deleted.)
True or False: in Python, a list only contains a group of values of the same type.
False. It can contain items of variable data types.
True or False: The order of items in a list is preserved.
True
How is a list created?
Using square brackets containing comma-separated values.
ie: my_list = [0, 5.5, “string”, 8]
True or False: in Python, a list contains a group of values of various type.
True
How are tuples created?
Via a number of values separated by commas.
ie: my_tuple = 0, 5.5, “string”, 8
or: my_tuple = (0, 5.5, “string”, 8)
How is an empty set created?
By using the method set().
ie: my_set = set()
How is a set with at least one element created?
By using curly braces and comma separated values.
ie: my_set = {0, 5.5, “string”, 8}
What are the values in set3?
set1 = {1, 2, 3}
set2 = {3, 4, 5}
set3 = set1 & set2
{3}
What are the values in set3?
set1 = {1, 2, 3}
set2 = {3, 4, 5}
set3 = set1 | set2
{1, 2, 3, 4, 5}q
What are the values in set3?
set1 = {1, 2, 3}
set2 = {3, 4, 5}
set3 = set1 - set2
{1, 2}