[]
) syntax for creating a list0
) with square brackets ([]
) as well()
) syntax for creating a tuple0
) with square brackets ([]
)key: value
{}
) with key and value separated by colon (:
)[]
)A set is (another) data structure
Helpful ways of thinking about it
Do not store items in the order you created them
Do not allow repeated items to be stored
Cannot use square brackets to retrieve an item
Use set()
to initiate an empty set
Use len()
to get number of items
Use for x in set
to iterate over the elements in a set
.add(value)
adds an element to the set.discard(value)
discards the specified valueYou can also use the operator in
and the function len()
with sets
Use the function set()
to convert a list to a set, and list()
to convert a set into a list
numbers_list = [2, -1, -2, 1, 3, 4, 1, 2]
numbers_list # evaluate this line
numbers_set = set(numbers_list)
numbers_set # evaluate this line
numbers_set.add(1)
numbers_set.add(2)
numbers_set # evaluate this line
numbers_set.add(5)
numbers_set # evaluate this line
numbers_set.discard(6)
numbers_set.discard(1)
numbers_set # evaluate this line
[2, -1, -2, 1, 3, 4, 1, 2]
You have 10 minutes to complete the quiz
main()
, no test casesBuilt-in functions you can use: round()
, input()
, float()
, str()
, int()
, len()
, range()
— you don’t have to use all of these
count_names
has_duplicates
*values
True
if there are repeated elements in values
, False
otherwise