Improve Python code for importing modules.
This commit is contained in:
parent
1e49574332
commit
5aacf2dfe0
@ -4,10 +4,11 @@ Created Time: 2022-11-25
|
|||||||
Author: Krahets (krahets@163.com)
|
Author: Krahets (krahets@163.com)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys, os.path as osp
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__))))
|
sys.path.append(str(Path(__file__).parent.parent))
|
||||||
from modules import *
|
from modules import ListNode, print_linked_list
|
||||||
|
|
||||||
|
|
||||||
def insert(n0: ListNode, P: ListNode):
|
def insert(n0: ListNode, P: ListNode):
|
||||||
|
@ -43,7 +43,7 @@ if __name__ == "__main__":
|
|||||||
for i in range(len(nums)):
|
for i in range(len(nums)):
|
||||||
tmp.append(nums[i])
|
tmp.append(nums[i])
|
||||||
print(f"\n通过索引遍历列表得到 tmp = {tmp}")
|
print(f"\n通过索引遍历列表得到 tmp = {tmp}")
|
||||||
|
|
||||||
tmp.clear()
|
tmp.clear()
|
||||||
for num in nums:
|
for num in nums:
|
||||||
tmp.append(num)
|
tmp.append(num)
|
||||||
|
@ -4,11 +4,6 @@ Created Time: 2023-04-15
|
|||||||
Author: Krahets (krahets@163.com)
|
Author: Krahets (krahets@163.com)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys, os.path as osp
|
|
||||||
|
|
||||||
sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__))))
|
|
||||||
from modules import *
|
|
||||||
|
|
||||||
|
|
||||||
def backtrack(
|
def backtrack(
|
||||||
state: list[int], choices: list[int], selected: list[bool], res: list[list[int]]
|
state: list[int], choices: list[int], selected: list[bool], res: list[list[int]]
|
||||||
|
@ -4,11 +4,6 @@ Created Time: 2023-04-15
|
|||||||
Author: Krahets (krahets@163.com)
|
Author: Krahets (krahets@163.com)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys, os.path as osp
|
|
||||||
|
|
||||||
sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__))))
|
|
||||||
from modules import *
|
|
||||||
|
|
||||||
|
|
||||||
def backtrack(
|
def backtrack(
|
||||||
state: list[int], choices: list[int], selected: list[bool], res: list[list[int]]
|
state: list[int], choices: list[int], selected: list[bool], res: list[list[int]]
|
||||||
|
@ -4,10 +4,11 @@ Created Time: 2023-04-15
|
|||||||
Author: Krahets (krahets@163.com)
|
Author: Krahets (krahets@163.com)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys, os.path as osp
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__))))
|
sys.path.append(str(Path(__file__).parent.parent))
|
||||||
from modules import *
|
from modules import TreeNode, print_tree, list_to_tree
|
||||||
|
|
||||||
|
|
||||||
def pre_order(root: TreeNode):
|
def pre_order(root: TreeNode):
|
||||||
|
@ -4,10 +4,11 @@ Created Time: 2023-04-15
|
|||||||
Author: Krahets (krahets@163.com)
|
Author: Krahets (krahets@163.com)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys, os.path as osp
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__))))
|
sys.path.append(str(Path(__file__).parent.parent))
|
||||||
from modules import *
|
from modules import TreeNode, print_tree, list_to_tree
|
||||||
|
|
||||||
|
|
||||||
def pre_order(root: TreeNode):
|
def pre_order(root: TreeNode):
|
||||||
|
@ -4,10 +4,11 @@ Created Time: 2023-04-15
|
|||||||
Author: Krahets (krahets@163.com)
|
Author: Krahets (krahets@163.com)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys, os.path as osp
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__))))
|
sys.path.append(str(Path(__file__).parent.parent))
|
||||||
from modules import *
|
from modules import TreeNode, print_tree, list_to_tree
|
||||||
|
|
||||||
|
|
||||||
def pre_order(root: TreeNode):
|
def pre_order(root: TreeNode):
|
||||||
|
@ -4,10 +4,11 @@ Created Time: 2023-04-15
|
|||||||
Author: Krahets (krahets@163.com)
|
Author: Krahets (krahets@163.com)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys, os.path as osp
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__))))
|
sys.path.append(str(Path(__file__).parent.parent))
|
||||||
from modules import *
|
from modules import TreeNode, print_tree, list_to_tree
|
||||||
|
|
||||||
|
|
||||||
def is_solution(state: list[TreeNode]) -> bool:
|
def is_solution(state: list[TreeNode]) -> bool:
|
||||||
|
@ -4,10 +4,11 @@ Created Time: 2022-11-25
|
|||||||
Author: Krahets (krahets@163.com)
|
Author: Krahets (krahets@163.com)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys, os.path as osp
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__))))
|
sys.path.append(str(Path(__file__).parent.parent))
|
||||||
from modules import *
|
from modules import ListNode, TreeNode, print_tree
|
||||||
|
|
||||||
|
|
||||||
def function() -> int:
|
def function() -> int:
|
||||||
|
@ -4,10 +4,11 @@ Created Time: 2023-07-15
|
|||||||
Author: Krahets (krahets@163.com)
|
Author: Krahets (krahets@163.com)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys, os.path as osp
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__))))
|
sys.path.append(str(Path(__file__).parent.parent))
|
||||||
from modules import *
|
from modules import TreeNode, print_tree
|
||||||
|
|
||||||
|
|
||||||
def dfs(
|
def dfs(
|
||||||
|
@ -4,10 +4,11 @@ Created Time: 2023-02-23
|
|||||||
Author: Krahets (krahets@163.com)
|
Author: Krahets (krahets@163.com)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys, os.path as osp
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__))))
|
sys.path.append(str(Path(__file__).parent.parent))
|
||||||
from modules import *
|
from modules import Vertex, vals_to_vets
|
||||||
|
|
||||||
|
|
||||||
class GraphAdjList:
|
class GraphAdjList:
|
||||||
|
@ -4,10 +4,11 @@ Created Time: 2023-02-23
|
|||||||
Author: Krahets (krahets@163.com)
|
Author: Krahets (krahets@163.com)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys, os.path as osp
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__))))
|
sys.path.append(str(Path(__file__).parent.parent))
|
||||||
from modules import *
|
from modules import Vertex, print_matrix
|
||||||
|
|
||||||
|
|
||||||
class GraphAdjMat:
|
class GraphAdjMat:
|
||||||
|
@ -4,10 +4,11 @@ Created Time: 2023-02-23
|
|||||||
Author: Krahets (krahets@163.com)
|
Author: Krahets (krahets@163.com)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys, os.path as osp
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__))))
|
sys.path.append(str(Path(__file__).parent.parent))
|
||||||
from modules import *
|
from modules import Vertex, vals_to_vets, vets_to_vals
|
||||||
from collections import deque
|
from collections import deque
|
||||||
from graph_adjacency_list import GraphAdjList
|
from graph_adjacency_list import GraphAdjList
|
||||||
|
|
||||||
|
@ -4,10 +4,11 @@ Created Time: 2023-02-23
|
|||||||
Author: Krahets (krahets@163.com)
|
Author: Krahets (krahets@163.com)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys, os.path as osp
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__))))
|
sys.path.append(str(Path(__file__).parent.parent))
|
||||||
from modules import *
|
from modules import Vertex, vets_to_vals, vals_to_vets
|
||||||
from graph_adjacency_list import GraphAdjList
|
from graph_adjacency_list import GraphAdjList
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,10 +4,11 @@ Created Time: 2023-06-15
|
|||||||
Author: Krahets (krahets@163.com)
|
Author: Krahets (krahets@163.com)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys, os.path as osp
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__))))
|
sys.path.append(str(Path(__file__).parent.parent))
|
||||||
from modules import *
|
from modules import ListNode
|
||||||
|
|
||||||
"""Driver Code"""
|
"""Driver Code"""
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -4,10 +4,11 @@ Created Time: 2022-12-14
|
|||||||
Author: msk397 (machangxinq@gmail.com)
|
Author: msk397 (machangxinq@gmail.com)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys, os.path as osp
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__))))
|
sys.path.append(str(Path(__file__).parent.parent))
|
||||||
from modules import *
|
from modules import print_dict
|
||||||
|
|
||||||
"""Driver Code"""
|
"""Driver Code"""
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -4,9 +4,10 @@ Created Time: 2023-06-13
|
|||||||
Author: Krahets (krahets@163.com)
|
Author: Krahets (krahets@163.com)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys, os.path as osp
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__))))
|
sys.path.append(str(Path(__file__).parent.parent))
|
||||||
from chapter_hashing.array_hash_map import Pair
|
from chapter_hashing.array_hash_map import Pair
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,9 +4,10 @@ Created Time: 2023-06-13
|
|||||||
Author: Krahets (krahets@163.com)
|
Author: Krahets (krahets@163.com)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys, os.path as osp
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__))))
|
sys.path.append(str(Path(__file__).parent.parent))
|
||||||
from chapter_hashing.array_hash_map import Pair
|
from chapter_hashing.array_hash_map import Pair
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,10 +4,11 @@ Created Time: 2023-02-23
|
|||||||
Author: Krahets (krahets@163.com)
|
Author: Krahets (krahets@163.com)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys, os.path as osp
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__))))
|
sys.path.append(str(Path(__file__).parent.parent))
|
||||||
from modules import *
|
from modules import print_heap
|
||||||
|
|
||||||
import heapq
|
import heapq
|
||||||
|
|
||||||
|
@ -4,10 +4,11 @@ Created Time: 2023-02-23
|
|||||||
Author: Krahets (krahets@163.com)
|
Author: Krahets (krahets@163.com)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys, os.path as osp
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__))))
|
sys.path.append(str(Path(__file__).parent.parent))
|
||||||
from modules import *
|
from modules import print_heap
|
||||||
|
|
||||||
|
|
||||||
class MaxHeap:
|
class MaxHeap:
|
||||||
|
@ -4,10 +4,11 @@ Created Time: 2023-06-10
|
|||||||
Author: Krahets (krahets@163.com)
|
Author: Krahets (krahets@163.com)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys, os.path as osp
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__))))
|
sys.path.append(str(Path(__file__).parent.parent))
|
||||||
from modules import *
|
from modules import print_heap
|
||||||
|
|
||||||
import heapq
|
import heapq
|
||||||
|
|
||||||
|
@ -4,9 +4,10 @@ Created Time: 2023-08-04
|
|||||||
Author: Krahets (krahets@163.com)
|
Author: Krahets (krahets@163.com)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys, os.path as osp
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__))))
|
sys.path.append(str(Path(__file__).parent.parent))
|
||||||
from binary_search_insertion import binary_search_insertion
|
from binary_search_insertion import binary_search_insertion
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,10 +4,11 @@ Created Time: 2022-11-26
|
|||||||
Author: timi (xisunyy@163.com)
|
Author: timi (xisunyy@163.com)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys, os.path as osp
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__))))
|
sys.path.append(str(Path(__file__).parent.parent))
|
||||||
from modules import *
|
from modules import ListNode, list_to_linked_list
|
||||||
|
|
||||||
|
|
||||||
def hashing_search_array(hmap: dict[int, int], target: int) -> int:
|
def hashing_search_array(hmap: dict[int, int], target: int) -> int:
|
||||||
|
@ -4,10 +4,11 @@ Created Time: 2022-11-26
|
|||||||
Author: timi (xisunyy@163.com)
|
Author: timi (xisunyy@163.com)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys, os.path as osp
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__))))
|
sys.path.append(str(Path(__file__).parent.parent))
|
||||||
from modules import *
|
from modules import ListNode, list_to_linked_list
|
||||||
|
|
||||||
|
|
||||||
def linear_search_array(nums: list[int], target: int) -> int:
|
def linear_search_array(nums: list[int], target: int) -> int:
|
||||||
|
@ -4,10 +4,11 @@ Created Time: 2022-12-01
|
|||||||
Author: Peng Chen (pengchzn@gmail.com)
|
Author: Peng Chen (pengchzn@gmail.com)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys, os.path as osp
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__))))
|
sys.path.append(str(Path(__file__).parent.parent))
|
||||||
from modules import *
|
from modules import ListNode
|
||||||
|
|
||||||
|
|
||||||
class LinkedListQueue:
|
class LinkedListQueue:
|
||||||
|
@ -4,10 +4,11 @@ Created Time: 2022-11-29
|
|||||||
Author: Peng Chen (pengchzn@gmail.com)
|
Author: Peng Chen (pengchzn@gmail.com)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys, os.path as osp
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__))))
|
sys.path.append(str(Path(__file__).parent.parent))
|
||||||
from modules import *
|
from modules import ListNode
|
||||||
|
|
||||||
|
|
||||||
class LinkedListStack:
|
class LinkedListStack:
|
||||||
|
@ -4,10 +4,11 @@ Created Time: 2023-07-19
|
|||||||
Author: Krahets (krahets@163.com)
|
Author: Krahets (krahets@163.com)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys, os.path as osp
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__))))
|
sys.path.append(str(Path(__file__).parent.parent))
|
||||||
from modules import *
|
from modules import TreeNode, list_to_tree, print_tree
|
||||||
|
|
||||||
|
|
||||||
class ArrayBinaryTree:
|
class ArrayBinaryTree:
|
||||||
|
@ -4,10 +4,11 @@ Created Time: 2022-12-20
|
|||||||
Author: a16su (lpluls001@gmail.com)
|
Author: a16su (lpluls001@gmail.com)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys, os.path as osp
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__))))
|
sys.path.append(str(Path(__file__).parent.parent))
|
||||||
from modules import *
|
from modules import TreeNode, print_tree
|
||||||
|
|
||||||
|
|
||||||
class AVLTree:
|
class AVLTree:
|
||||||
|
@ -4,10 +4,11 @@ Created Time: 2022-12-20
|
|||||||
Author: a16su (lpluls001@gmail.com)
|
Author: a16su (lpluls001@gmail.com)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys, os.path as osp
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__))))
|
sys.path.append(str(Path(__file__).parent.parent))
|
||||||
from modules import *
|
from modules import TreeNode, print_tree
|
||||||
|
|
||||||
|
|
||||||
class BinarySearchTree:
|
class BinarySearchTree:
|
||||||
|
@ -4,10 +4,11 @@ Created Time: 2022-12-20
|
|||||||
Author: a16su (lpluls001@gmail.com)
|
Author: a16su (lpluls001@gmail.com)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys, os.path as osp
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__))))
|
sys.path.append(str(Path(__file__).parent.parent))
|
||||||
from modules import *
|
from modules import TreeNode, print_tree
|
||||||
|
|
||||||
|
|
||||||
"""Driver Code"""
|
"""Driver Code"""
|
||||||
|
@ -4,10 +4,11 @@ Created Time: 2022-12-20
|
|||||||
Author: a16su (lpluls001@gmail.com)
|
Author: a16su (lpluls001@gmail.com)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys, os.path as osp
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__))))
|
sys.path.append(str(Path(__file__).parent.parent))
|
||||||
from modules import *
|
from modules import TreeNode, list_to_tree, print_tree
|
||||||
from collections import deque
|
from collections import deque
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,10 +4,11 @@ Created Time: 2022-12-20
|
|||||||
Author: a16su (lpluls001@gmail.com)
|
Author: a16su (lpluls001@gmail.com)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys, os.path as osp
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__))))
|
sys.path.append(str(Path(__file__).parent.parent))
|
||||||
from modules import *
|
from modules import TreeNode, list_to_tree, print_tree
|
||||||
|
|
||||||
|
|
||||||
def pre_order(root: TreeNode | None):
|
def pre_order(root: TreeNode | None):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user