This file contains hidden or 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
| import os | |
| print(os.path.dirname(os.path.realpath(__file__))) |
This file contains hidden or 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
| import sys | |
| sys.version_info |
This file contains hidden or 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
| """ | |
| sys: | |
| Return the size of an object in bytes.The object can be any type of object. | |
| All built-in objects will return correct results, but this does not have to | |
| hold true for third-party extensions as it is implementation specific. | |
| pandas/polars: | |
| Returns the size of an object in KB/MB/GB. Checking the dtypes will be | |
| informative (e.g., float64 likely to use more space than int8). | |
| """ |
This file contains hidden or 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
| import os | |
| os.path.exists('xxx.txt') |
This file contains hidden or 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
| a = "x" | |
| b = 1 | |
| c = 1.2 | |
| print(a.__class__.__name__) # str | |
| print(b.__class__.__name__) # int | |
| print(c.__class__.__name__) # float |
This file contains hidden or 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
| a = 1 | |
| 'a' in locals() # True | |
| 'z' in locals() # False | |
| 'a' in globals() # True | |
| 'z' in globals() # False |
This file contains hidden or 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
| mylist = ['a', 'b', 'c', 'd'] | |
| # Remove item 1 | |
| mylist.pop(1) #'b' | |
| print(l) #['a', 'c', 'd'] | |
| # Remove item with value 'd' | |
| mylist.remove('d') | |
| print(l) # ['a', 'c'] |
This file contains hidden or 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
| import heapq | |
| print(heapq.nlargest(3, [10, 5, 3, 8, 4, 2])) # [10, 8, 5] |
This file contains hidden or 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
| l1 = [1,2,3] | |
| l2 = [4,5,6] | |
| print(list(zip(l1, l2))) #[(1, 4), (2, 5), (3, 6)] |
This file contains hidden or 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
| z = zip(*[(1, 2), (3, 4), (5, 6)]) | |
| l1, l2 = map(list, z) | |
| print(l1) #[1, 3, 5] | |
| print(l2) #[2, 4, 6] |
OlderNewer