Skip to content

Commit f7d7011

Browse files
author
phk
committed
added description for available datastructures
1 parent 57520f7 commit f7d7011

File tree

4 files changed

+80
-24
lines changed

4 files changed

+80
-24
lines changed

20_sets.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
1-
# python3 sets: introduced set literals and comprehensions (see PEP-3100) which allowed us to avoid intermediate lists
1+
# python3 datastructure sets: introduced set literals and comprehensions (see PEP-3100) which allowed us to avoid intermediate lists
22

33
"""
4-
Python3: List vs Tuple vs Set vs Dictionary
5-
Lists - for ordered sequence of indexed objects
6-
Tuple - can be considered as immutable/hashable list
7-
Python Set - unique list
8-
Python Dictionary / dict - pair of key and values
4+
[Python3: List vs Tuple vs Set vs Dictionary]
5+
6+
Lists: for ordered collection of items or sequence of objects,
7+
indexed, _not_ hashable
8+
9+
Tuples: can be considered as immutable list,
10+
elements can't be added, removed or replaced after declaration,
11+
hashable, _not_ indexed
12+
13+
Sets: unique list w/o order and duplicates,
14+
fast + union/intersection operations/methods
15+
not hashable
16+
17+
Dict: pair of key and values
918
"""
1019

1120
# define set (note the missing colon on end of line)

21_dictionaries.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
1-
# python3 dictionaries:
1+
# python3 datastructure dictionaries:
22

33
"""
4-
Python3: List vs Tuple vs Set vs Dictionary
5-
Lists - for ordered sequence of indexed objects
6-
Tuple - can be considered as immutable/hashable list
7-
Python Set - unique list
8-
Python Dictionary / dict - pair of key and values
4+
[Python3: List vs Tuple vs Set vs Dictionary]
5+
6+
Lists: for ordered collection of items or sequence of objects,
7+
indexed, _not_ hashable
8+
9+
Tuples: can be considered as immutable list,
10+
elements can't be added, removed or replaced after declaration,
11+
hashable, _not_ indexed
12+
13+
Sets: unique list w/o order and duplicates,
14+
fast + union/intersection operations/methods
15+
not hashable
16+
17+
Dict: pair of key and values
918
"""
1019

1120
# import some functions and classes [doesn't work if filenames start w/ numbers eg. 98_test]

23_tuples.py

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,38 @@
1-
# python3 tuples: can be considered as immutable/hashable list
1+
# python3 datastructure tuples: can be considered as immutable/hashable list
22

33
"""
4-
Python3: List vs Tuple vs Set vs Dictionary
5-
Lists - for ordered sequence of indexed objects
6-
Tuple - can be considered as immutable/hashable list
7-
Python Set - unique list
8-
Python Dictionary / dict - pair of key and values
4+
[Python3: List vs Tuple vs Set vs Dictionary]
5+
6+
Lists: for ordered collection of items or sequence of objects,
7+
indexed, _not_ hashable
8+
9+
Tuples: can be considered as immutable list,
10+
elements can't be added, removed or replaced after declaration,
11+
hashable, _not_ indexed
12+
13+
Sets: unique list w/o order and duplicates,
14+
fast + union/intersection operations/methods
15+
not hashable
16+
17+
Dict: pair of key and values
918
"""
19+
20+
# tuple declaration
21+
s1 = (1, 2, 3, 4, 1)
22+
s2 = ('jan','feb','mar','apr','may','june','july','aug','sep','oct','dec','jan')
23+
s3 = ('a', 0, 3.14)
24+
25+
print(s1)
26+
print(type(s1))
27+
print(s2)
28+
print(type(s2))
29+
print(s3)
30+
print(type(s3))
31+
32+
# operations: count() counts given element/object in tuple, index() gives index of given element/object in tuple
33+
print('print(s1.count(1))')
34+
print(s1.count(1))
35+
print("print(s2.count('jan'))")
36+
print(s2.count('feb'))
37+
print('print(s3.index(0))')
38+
print(s3.index('a'))

9_lists.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
1-
# python3 lists: ordered sequence of objects
1+
# python3 datastructure lists: ordered sequence of objects
22

33
"""
4-
Python3: List vs Tuple vs Set vs Dictionary
5-
Lists - for ordered sequence of indexed objects
6-
Tuple - can be considered as immutable/hashable list
7-
Python Set - unique list
8-
Python Dictionary / dict - pair of key and values
4+
[Python3: List vs Tuple vs Set vs Dictionary]
5+
6+
Lists: for ordered collection of items or sequence of objects,
7+
indexed, _not_ hashable
8+
9+
Tuples: can be considered as immutable list,
10+
elements can't be added, removed or replaced after declaration,
11+
hashable, _not_ indexed
12+
13+
Sets: unique list w/o order and duplicates,
14+
fast + union/intersection operations/methods
15+
not hashable
16+
17+
Dict: pair of key and values
918
"""
1019

1120
# list indexes

0 commit comments

Comments
 (0)