Skip to content

Commit

Permalink
added description for available datastructures
Browse files Browse the repository at this point in the history
  • Loading branch information
phk committed Aug 11, 2021
1 parent 57520f7 commit f7d7011
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 24 deletions.
21 changes: 15 additions & 6 deletions 20_sets.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
# python3 sets: introduced set literals and comprehensions (see PEP-3100) which allowed us to avoid intermediate lists
# python3 datastructure sets: introduced set literals and comprehensions (see PEP-3100) which allowed us to avoid intermediate lists

"""
Python3: List vs Tuple vs Set vs Dictionary
Lists - for ordered sequence of indexed objects
Tuple - can be considered as immutable/hashable list
Python Set - unique list
Python Dictionary / dict - pair of key and values
[Python3: List vs Tuple vs Set vs Dictionary]
Lists: for ordered collection of items or sequence of objects,
indexed, _not_ hashable
Tuples: can be considered as immutable list,
elements can't be added, removed or replaced after declaration,
hashable, _not_ indexed
Sets: unique list w/o order and duplicates,
fast + union/intersection operations/methods
not hashable
Dict: pair of key and values
"""

# define set (note the missing colon on end of line)
Expand Down
21 changes: 15 additions & 6 deletions 21_dictionaries.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
# python3 dictionaries:
# python3 datastructure dictionaries:

"""
Python3: List vs Tuple vs Set vs Dictionary
Lists - for ordered sequence of indexed objects
Tuple - can be considered as immutable/hashable list
Python Set - unique list
Python Dictionary / dict - pair of key and values
[Python3: List vs Tuple vs Set vs Dictionary]
Lists: for ordered collection of items or sequence of objects,
indexed, _not_ hashable
Tuples: can be considered as immutable list,
elements can't be added, removed or replaced after declaration,
hashable, _not_ indexed
Sets: unique list w/o order and duplicates,
fast + union/intersection operations/methods
not hashable
Dict: pair of key and values
"""

# import some functions and classes [doesn't work if filenames start w/ numbers eg. 98_test]
Expand Down
41 changes: 35 additions & 6 deletions 23_tuples.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,38 @@
# python3 tuples: can be considered as immutable/hashable list
# python3 datastructure tuples: can be considered as immutable/hashable list

"""
Python3: List vs Tuple vs Set vs Dictionary
Lists - for ordered sequence of indexed objects
Tuple - can be considered as immutable/hashable list
Python Set - unique list
Python Dictionary / dict - pair of key and values
[Python3: List vs Tuple vs Set vs Dictionary]
Lists: for ordered collection of items or sequence of objects,
indexed, _not_ hashable
Tuples: can be considered as immutable list,
elements can't be added, removed or replaced after declaration,
hashable, _not_ indexed
Sets: unique list w/o order and duplicates,
fast + union/intersection operations/methods
not hashable
Dict: pair of key and values
"""

# tuple declaration
s1 = (1, 2, 3, 4, 1)
s2 = ('jan','feb','mar','apr','may','june','july','aug','sep','oct','dec','jan')
s3 = ('a', 0, 3.14)

print(s1)
print(type(s1))
print(s2)
print(type(s2))
print(s3)
print(type(s3))

# operations: count() counts given element/object in tuple, index() gives index of given element/object in tuple
print('print(s1.count(1))')
print(s1.count(1))
print("print(s2.count('jan'))")
print(s2.count('feb'))
print('print(s3.index(0))')
print(s3.index('a'))
21 changes: 15 additions & 6 deletions 9_lists.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
# python3 lists: ordered sequence of objects
# python3 datastructure lists: ordered sequence of objects

"""
Python3: List vs Tuple vs Set vs Dictionary
Lists - for ordered sequence of indexed objects
Tuple - can be considered as immutable/hashable list
Python Set - unique list
Python Dictionary / dict - pair of key and values
[Python3: List vs Tuple vs Set vs Dictionary]
Lists: for ordered collection of items or sequence of objects,
indexed, _not_ hashable
Tuples: can be considered as immutable list,
elements can't be added, removed or replaced after declaration,
hashable, _not_ indexed
Sets: unique list w/o order and duplicates,
fast + union/intersection operations/methods
not hashable
Dict: pair of key and values
"""

# list indexes
Expand Down

0 comments on commit f7d7011

Please sign in to comment.