refactor: Replace list() and dict() calls with literals (#7198)

This commit is contained in:
Caeden 2022-10-15 02:07:03 +01:00 committed by GitHub
parent dcca5351c9
commit 6e69181d1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 14 additions and 14 deletions

View File

@ -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

View File

@ -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.

View File

@ -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:

View File

@ -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)

View File

@ -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 (

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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:

View File

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