Skip to content

Commit

Permalink
Fix formatting and linting
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyannn committed Jan 14, 2024
1 parent fd44cdf commit a20ba9d
Show file tree
Hide file tree
Showing 19 changed files with 56 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/linters/.flake8
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[flake8]
max-line-length = 200
extend-ignore = E203, E704
extend-ignore = E203, E704, E741
9 changes: 4 additions & 5 deletions arithmetic_expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
from itertools import pairwise
from math import factorial


## METHOD 1
# METHOD 1


class Reader:
Expand Down Expand Up @@ -106,7 +105,7 @@ def consume_or():
return int(consume_brackets())


## METHOD 2
# METHOD 2


class PostfixConverter:
Expand All @@ -120,7 +119,7 @@ def __init__(
self.whitespace = whitespace
self.open = {brackets[i]: brackets[i + 1] for i in range(0, len(brackets), 2)}
self.close = {brackets[i + 1]: brackets[i] for i in range(0, len(brackets), 2)}

operator_order = operator_order or []
precedence = {}
for p, ops in enumerate(reversed(operator_order)):
Expand Down Expand Up @@ -160,7 +159,7 @@ def convert(self, expression) -> list:
p = self.precedence_unary[ch]
elif ch in self.precedence:
p = self.precedence[ch]
else:
else:
yield ch
prefix_context = False
continue
Expand Down
6 changes: 4 additions & 2 deletions averages.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import re
import unittest
from math import nan, isnan
from math import isnan, nan
from statistics import mean
from typing import Optional

Expand Down Expand Up @@ -197,7 +197,9 @@ def test_compute_average_expression(self):

def test_dump_arguments(self):
self.assertEqual(dump_arguments([("arg", 0.056)], accuracy=2), "arg=0.06")
self.assertEqual(dump_arguments([("a", 1), ("b", .24)], accuracy=1), "a=1.0 b=0.2")
self.assertEqual(
dump_arguments([("a", 1), ("b", 0.24)], accuracy=1), "a=1.0 b=0.2"
)


if __name__ == "__main__":
Expand Down
6 changes: 3 additions & 3 deletions dynamic-2d.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys
from functools import cache


def main():
n, m = (int(v) for v in input().split())
table = [[int(v) for v in input().split()] for _ in range(n)]
Expand All @@ -14,12 +14,12 @@ def neighbours(x, y):
def answer(x, y):
if x == 0 and y == 1:
return 0
if not (1 <= x <= m and 1 <= y <=n):
if not (1 <= x <= m and 1 <= y <= n):
return float("inf")
return table[y - 1][x - 1] + min(answer(*n) for n in neighbours(x, y))

print(answer(m, n))


if __name__ == '__main__':
if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion lc_0014_longest_common.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""14. Longest Common Prefix"""
import unittest
from itertools import takewhile, zip_longest
from typing import List
import unittest


class Solution1:
Expand Down
5 changes: 3 additions & 2 deletions lc_0094_binary_in_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@
Memory Usage: 14.4 MB, less than 14.09% of Python3 online submissions for Binary Tree Inorder Traversal.
"""

from typing import List, Optional


# Definition for a binary tree node.
class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right

from typing import List, Optional


class Solution:
def inorderTraversal(self, root: Optional[TreeNode]) -> List[int]:
Expand Down
6 changes: 4 additions & 2 deletions lc_0212_word_search_original.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from collections import defaultdict, deque
from typing import List


class Solution:
def findWords(self, board: List[List[str]], words: List[str]) -> List[str]:
m, n = len(board), len(board[0])
n = len(board[0])
B = n + 2

def g_enumerate():
Expand All @@ -13,7 +15,7 @@ def g_enumerate():

def neighbors(p):
"""List of neighboring cells"""
return (p + 1, p - 1, p + R, p - R)
return p + 1, p - 1, p + B, p - B

grid = defaultdict(lambda: None) | dict(g_enumerate())
chars = set(grid.values())
Expand Down
3 changes: 2 additions & 1 deletion lc_0329_longest_path_in_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
"""

from collections import defaultdict
from itertools import count
from typing import List


class Solution:
def longestIncreasingPath(self, matrix: List[List[int]]) -> int:
m, n = len(matrix), len(matrix[0])
R = n + 2 # 😕 Now unused
_ = n + 2 # 😕 Now unused

# 😕 This has been rewritten back to regular pairs
def m_enumerate():
Expand Down
2 changes: 1 addition & 1 deletion lc_0354_envelopes.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import unittest
from bisect import bisect_left
from math import inf
from typing import List
import unittest


class SolutionShort:
Expand Down
2 changes: 1 addition & 1 deletion lc_0431_nary_to_binary.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""431. Encode N-ary Tree to Binary Tree"""

import operator
from typing import Optional
import unittest
from typing import Optional


class NAryNode:
Expand Down
2 changes: 1 addition & 1 deletion lc_0460_lfu_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
Memory Usage: 77.7 MB, less than 98.42% of Python3 online submissions for LFU Cache.
"""

from collections import defaultdict
import unittest
from collections import defaultdict


def debug(*_):
Expand Down
2 changes: 1 addition & 1 deletion lc_0621_task_scheduler.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import unittest
from collections import Counter
from itertools import count
from typing import List
import unittest


class Solution:
Expand Down
2 changes: 1 addition & 1 deletion lc_0691_stickers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
Memory Usage: 15.3 MB, less than 28.82% of Python3 online submissions for Stickers to Spell Word.
"""

import unittest
from collections import Counter
from functools import cache
from typing import List
import unittest


def subtract(a, b, n=1):
Expand Down
2 changes: 1 addition & 1 deletion lc_0697_degree.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"""

import unittest
from collections import defaultdict
from typing import List
import unittest


class Solution:
Expand Down
2 changes: 1 addition & 1 deletion lc_0994_rotting_oranges.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
Memory Usage: 14.4 MB, less than 39.37% of Python3 online submissions for Rotting Oranges.
"""
import unittest
from itertools import count
from typing import List
import unittest


class Solution:
Expand Down
4 changes: 3 additions & 1 deletion lc_1192_critical_edges.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""1192. Critical Connections in a Network
There are n servers numbered from 0 to n - 1 connected by undirected server-to-server connections forming a network where connections[i] = [ai, bi] represents a connection between servers ai and bi. Any server can reach other servers directly or indirectly through the network.
There are n servers numbered from 0 to n - 1 connected by undirected server-to-server connections forming a network
where connections[i] = [ai, bi] represents a connection between servers ai and bi. Any server can reach other servers
directly or indirectly through the network.
A critical connection is a connection that, if removed, will make some servers unable to reach some other server.
Expand Down
4 changes: 2 additions & 2 deletions lc_2132_stamp_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
"""

from itertools import chain
from typing import List
import random
import unittest
from itertools import chain
from typing import List


def add_arrays(arrays):
Expand Down
16 changes: 9 additions & 7 deletions lc_template.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import bisect
from itertools import *
from string import *
from collections import *
# import bisect
import unittest

# from collections import *
# from itertools import *
# from string import *


# noinspection PyMethodMayBeStatic
class MyTestCase(unittest.TestCase):
Expand All @@ -14,12 +15,13 @@ def test_passing(self):
assert 2 + 2 == 4

def test_failing1(self):
# assert 2 + 2 == 5
# assert 2 + 2 == 5
pass

def test_failing2(self):
# assert 2 + 2 == 5
# assert 2 + 2 == 5
pass


if __name__ == "__main__":
unittest.main()
15 changes: 13 additions & 2 deletions test_arithmetic_expression.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
import operator
import unittest
from arithmetic_expression import *

from arithmetic_expression import (
ALL_OPS,
DIGITS,
Logger,
PostfixConverter,
Reader,
analyze1,
analyze2,
eval_postfix,
)


class ReaderTests(unittest.TestCase):
Expand Down Expand Up @@ -53,7 +64,7 @@ def check_conversions(
try:
true_value = eval(example)
self.assertEqual(value, true_value)
except:
except Exception:
pass

def test_empty(self):
Expand Down

0 comments on commit a20ba9d

Please sign in to comment.