-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added description for available datastructures
- Loading branch information
phk
committed
Aug 11, 2021
1 parent
57520f7
commit f7d7011
Showing
4 changed files
with
80 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters