Skip to content

Commit

Permalink
refactor: Replace list() and dict() calls with literals (TheAlgor…
Browse files Browse the repository at this point in the history
  • Loading branch information
CaedenPH authored Oct 15, 2022
1 parent dcca535 commit 6e69181
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion data_structures/binary_tree/binary_search_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion data_structures/heap/heap_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion data_structures/trie/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

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:
Expand Down
2 changes: 1 addition & 1 deletion graphs/frequent_pattern_graph_miner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion maths/greedy_coin_change.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
4 changes: 2 additions & 2 deletions other/davisb_putnamb_logemannb_loveland.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion project_euler/problem_107/sol1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions searches/tabu_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ 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:
dict_of_neighbours[line.split()[0]].append(
[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:
Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions sorts/msd_radix_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion strings/aho_corasick.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

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": []}
)
Expand Down

0 comments on commit 6e69181

Please sign in to comment.