diff --git a/data_structures/binary_tree/binary_search_tree.py b/data_structures/binary_tree/binary_search_tree.py index b9af23dc8..51a651be0 100644 --- a/data_structures/binary_tree/binary_search_tree.py +++ b/data_structures/binary_tree/binary_search_tree.py @@ -160,7 +160,7 @@ def postorder(curr_node): """ postOrder (left, right, self) """ - node_list = list() + node_list = [] if curr_node is not None: node_list = postorder(curr_node.left) + postorder(curr_node.right) + [curr_node] return node_list diff --git a/data_structures/heap/heap_generic.py b/data_structures/heap/heap_generic.py index e7831cd45..b4d7019f4 100644 --- a/data_structures/heap/heap_generic.py +++ b/data_structures/heap/heap_generic.py @@ -9,7 +9,7 @@ class Heap: def __init__(self, key: Callable | None = None) -> None: # Stores actual heap items. - self.arr: list = list() + self.arr: list = [] # Stores indexes of each item for supporting updates and deletion. self.pos_map: dict = {} # Stores current size of heap. diff --git a/data_structures/trie/trie.py b/data_structures/trie/trie.py index 162d08d1d..46b93a499 100644 --- a/data_structures/trie/trie.py +++ b/data_structures/trie/trie.py @@ -8,7 +8,7 @@ longest word)) lookup time making it an optimal approach when space is not an is class TrieNode: def __init__(self) -> None: - self.nodes: dict[str, TrieNode] = dict() # Mapping from char to TrieNode + self.nodes: dict[str, TrieNode] = {} # Mapping from char to TrieNode self.is_leaf = False def insert_many(self, words: list[str]) -> None: diff --git a/graphs/frequent_pattern_graph_miner.py b/graphs/frequent_pattern_graph_miner.py index a5ecbe6e8..1d26702a4 100644 --- a/graphs/frequent_pattern_graph_miner.py +++ b/graphs/frequent_pattern_graph_miner.py @@ -54,7 +54,7 @@ def get_frequency_table(edge_array): Returns Frequency Table """ distinct_edge = get_distinct_edge(edge_array) - frequency_table = dict() + frequency_table = {} for item in distinct_edge: bit = get_bitcode(edge_array, item) diff --git a/maths/greedy_coin_change.py b/maths/greedy_coin_change.py index 5233ee1cb..29c2f1803 100644 --- a/maths/greedy_coin_change.py +++ b/maths/greedy_coin_change.py @@ -74,7 +74,7 @@ def find_minimum_change(denominations: list[int], value: str) -> list[int]: # Driver Code if __name__ == "__main__": - denominations = list() + denominations = [] value = "0" if ( diff --git a/other/davisb_putnamb_logemannb_loveland.py b/other/davisb_putnamb_logemannb_loveland.py index 03d60a9a1..3110515d5 100644 --- a/other/davisb_putnamb_logemannb_loveland.py +++ b/other/davisb_putnamb_logemannb_loveland.py @@ -199,7 +199,7 @@ def find_pure_symbols( {'A1': True, 'A2': False, 'A3': True, 'A5': False} """ pure_symbols = [] - assignment: dict[str, bool | None] = dict() + assignment: dict[str, bool | None] = {} literals = [] for clause in clauses: @@ -264,7 +264,7 @@ def find_unit_clauses( n_count += 1 if f_count == len(clause) - 1 and n_count == 1: unit_symbols.append(sym) - assignment: dict[str, bool | None] = dict() + assignment: dict[str, bool | None] = {} for i in unit_symbols: symbol = i[:2] assignment[symbol] = len(i) == 2 diff --git a/project_euler/problem_107/sol1.py b/project_euler/problem_107/sol1.py index 048cf033d..b3f5685b9 100644 --- a/project_euler/problem_107/sol1.py +++ b/project_euler/problem_107/sol1.py @@ -100,7 +100,7 @@ def solution(filename: str = "p107_network.txt") -> int: script_dir: str = os.path.abspath(os.path.dirname(__file__)) network_file: str = os.path.join(script_dir, filename) adjacency_matrix: list[list[str]] - edges: dict[EdgeT, int] = dict() + edges: dict[EdgeT, int] = {} data: list[str] edge1: int edge2: int diff --git a/searches/tabu_search.py b/searches/tabu_search.py index 45ce19d46..3e1728286 100644 --- a/searches/tabu_search.py +++ b/searches/tabu_search.py @@ -51,7 +51,7 @@ def generate_neighbours(path): with open(path) as f: for line in f: if line.split()[0] not in dict_of_neighbours: - _list = list() + _list = [] _list.append([line.split()[1], line.split()[2]]) dict_of_neighbours[line.split()[0]] = _list else: @@ -59,7 +59,7 @@ def generate_neighbours(path): [line.split()[1], line.split()[2]] ) if line.split()[1] not in dict_of_neighbours: - _list = list() + _list = [] _list.append([line.split()[0], line.split()[2]]) dict_of_neighbours[line.split()[1]] = _list else: @@ -206,7 +206,7 @@ def tabu_search( """ count = 1 solution = first_solution - tabu_list = list() + tabu_list = [] best_cost = distance_of_first_solution best_solution_ever = solution diff --git a/sorts/msd_radix_sort.py b/sorts/msd_radix_sort.py index 3cdec4bd0..7430fc5a6 100644 --- a/sorts/msd_radix_sort.py +++ b/sorts/msd_radix_sort.py @@ -52,8 +52,8 @@ def _msd_radix_sort(list_of_ints: list[int], bit_position: int) -> list[int]: if bit_position == 0 or len(list_of_ints) in [0, 1]: return list_of_ints - zeros = list() - ones = list() + zeros = [] + ones = [] # Split numbers based on bit at bit_position from the right for number in list_of_ints: if (number >> (bit_position - 1)) & 1: diff --git a/strings/aho_corasick.py b/strings/aho_corasick.py index b9a6a8072..2d2f562df 100644 --- a/strings/aho_corasick.py +++ b/strings/aho_corasick.py @@ -5,7 +5,7 @@ from collections import deque class Automaton: def __init__(self, keywords: list[str]): - self.adlist: list[dict] = list() + self.adlist: list[dict] = [] self.adlist.append( {"value": "", "next_states": [], "fail_state": 0, "output": []} )