Skip to content

Commit 6e69181

Browse files
authored
refactor: Replace list() and dict() calls with literals (TheAlgorithms#7198)
1 parent dcca535 commit 6e69181

File tree

10 files changed

+14
-14
lines changed

10 files changed

+14
-14
lines changed

data_structures/binary_tree/binary_search_tree.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def postorder(curr_node):
160160
"""
161161
postOrder (left, right, self)
162162
"""
163-
node_list = list()
163+
node_list = []
164164
if curr_node is not None:
165165
node_list = postorder(curr_node.left) + postorder(curr_node.right) + [curr_node]
166166
return node_list

data_structures/heap/heap_generic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Heap:
99

1010
def __init__(self, key: Callable | None = None) -> None:
1111
# Stores actual heap items.
12-
self.arr: list = list()
12+
self.arr: list = []
1313
# Stores indexes of each item for supporting updates and deletion.
1414
self.pos_map: dict = {}
1515
# Stores current size of heap.

data_structures/trie/trie.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
class TrieNode:
1010
def __init__(self) -> None:
11-
self.nodes: dict[str, TrieNode] = dict() # Mapping from char to TrieNode
11+
self.nodes: dict[str, TrieNode] = {} # Mapping from char to TrieNode
1212
self.is_leaf = False
1313

1414
def insert_many(self, words: list[str]) -> None:

graphs/frequent_pattern_graph_miner.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def get_frequency_table(edge_array):
5454
Returns Frequency Table
5555
"""
5656
distinct_edge = get_distinct_edge(edge_array)
57-
frequency_table = dict()
57+
frequency_table = {}
5858

5959
for item in distinct_edge:
6060
bit = get_bitcode(edge_array, item)

maths/greedy_coin_change.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def find_minimum_change(denominations: list[int], value: str) -> list[int]:
7474
# Driver Code
7575
if __name__ == "__main__":
7676

77-
denominations = list()
77+
denominations = []
7878
value = "0"
7979

8080
if (

other/davisb_putnamb_logemannb_loveland.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def find_pure_symbols(
199199
{'A1': True, 'A2': False, 'A3': True, 'A5': False}
200200
"""
201201
pure_symbols = []
202-
assignment: dict[str, bool | None] = dict()
202+
assignment: dict[str, bool | None] = {}
203203
literals = []
204204

205205
for clause in clauses:
@@ -264,7 +264,7 @@ def find_unit_clauses(
264264
n_count += 1
265265
if f_count == len(clause) - 1 and n_count == 1:
266266
unit_symbols.append(sym)
267-
assignment: dict[str, bool | None] = dict()
267+
assignment: dict[str, bool | None] = {}
268268
for i in unit_symbols:
269269
symbol = i[:2]
270270
assignment[symbol] = len(i) == 2

project_euler/problem_107/sol1.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def solution(filename: str = "p107_network.txt") -> int:
100100
script_dir: str = os.path.abspath(os.path.dirname(__file__))
101101
network_file: str = os.path.join(script_dir, filename)
102102
adjacency_matrix: list[list[str]]
103-
edges: dict[EdgeT, int] = dict()
103+
edges: dict[EdgeT, int] = {}
104104
data: list[str]
105105
edge1: int
106106
edge2: int

searches/tabu_search.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ def generate_neighbours(path):
5151
with open(path) as f:
5252
for line in f:
5353
if line.split()[0] not in dict_of_neighbours:
54-
_list = list()
54+
_list = []
5555
_list.append([line.split()[1], line.split()[2]])
5656
dict_of_neighbours[line.split()[0]] = _list
5757
else:
5858
dict_of_neighbours[line.split()[0]].append(
5959
[line.split()[1], line.split()[2]]
6060
)
6161
if line.split()[1] not in dict_of_neighbours:
62-
_list = list()
62+
_list = []
6363
_list.append([line.split()[0], line.split()[2]])
6464
dict_of_neighbours[line.split()[1]] = _list
6565
else:
@@ -206,7 +206,7 @@ def tabu_search(
206206
"""
207207
count = 1
208208
solution = first_solution
209-
tabu_list = list()
209+
tabu_list = []
210210
best_cost = distance_of_first_solution
211211
best_solution_ever = solution
212212

sorts/msd_radix_sort.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ def _msd_radix_sort(list_of_ints: list[int], bit_position: int) -> list[int]:
5252
if bit_position == 0 or len(list_of_ints) in [0, 1]:
5353
return list_of_ints
5454

55-
zeros = list()
56-
ones = list()
55+
zeros = []
56+
ones = []
5757
# Split numbers based on bit at bit_position from the right
5858
for number in list_of_ints:
5959
if (number >> (bit_position - 1)) & 1:

strings/aho_corasick.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
class Automaton:
77
def __init__(self, keywords: list[str]):
8-
self.adlist: list[dict] = list()
8+
self.adlist: list[dict] = []
99
self.adlist.append(
1010
{"value": "", "next_states": [], "fail_state": 0, "output": []}
1111
)

0 commit comments

Comments
 (0)