-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNOTES_list_tuple_set_dictionary.txt
More file actions
38 lines (30 loc) · 1.12 KB
/
NOTES_list_tuple_set_dictionary.txt
File metadata and controls
38 lines (30 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
Reference: https://www.educative.io/answers/list-vs-tuple-vs-set-vs-dictionary-in-python
STRING - text ; IMMUTABLE
Cannot replace a single character directly because STRINGS are IMMUTABLE.
To replace specific character, you can transform it to a list then do your changes
LIST is a collection of ordered data. MUTABLE
append()
sorted()
reverse()
pop()
insert(index, value)
Search using the index
TUPLE is an ordered collection of data. IMMUTABLE-cannot be changed
CANNOT BE SORTED
CANNOT BE REVERSED
The order matters in a tuple
SET is an unordered collection. MUTABLE, NO DUPLICATE ITEMS
add()
CANNOT BE SORTED
CANNOT BE REVERSED
DICTIONARY is an unordered collection of data that stores data in key-value pairs.
MUTABLE, NO DUPLICATE ITEMS
push()
pop()
update()
sort()
search / get value using the key
CANNOT BE REVERSED directly - but you may sort then get first/last element
To navigate elements, use ____.items(), ____.keys(), ____.values()
# for x in dictionary_name.items():
Approach 2: store dictionary values in a list then sort/reverse as you need.