Adopt Python >= 3.8 assignment expressions using auto-walrus (#7737)

* Adopt Python >= 3.8 assignment expressions using auto-walrus

* updating DIRECTORY.md

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Christian Clauss 2022-10-28 15:54:54 +02:00 committed by GitHub
parent 15c93e5f4b
commit 19bff003aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 642 additions and 639 deletions

View File

@ -13,6 +13,11 @@ repos:
)$ )$
- id: requirements-txt-fixer - id: requirements-txt-fixer
- repo: https://github.com/MarcoGorelli/auto-walrus
rev: v0.2.1
hooks:
- id: auto-walrus
- repo: https://github.com/psf/black - repo: https://github.com/psf/black
rev: 22.10.0 rev: 22.10.0
hooks: hooks:

View File

@ -45,6 +45,7 @@
* [Count 1S Brian Kernighan Method](bit_manipulation/count_1s_brian_kernighan_method.py) * [Count 1S Brian Kernighan Method](bit_manipulation/count_1s_brian_kernighan_method.py)
* [Count Number Of One Bits](bit_manipulation/count_number_of_one_bits.py) * [Count Number Of One Bits](bit_manipulation/count_number_of_one_bits.py)
* [Gray Code Sequence](bit_manipulation/gray_code_sequence.py) * [Gray Code Sequence](bit_manipulation/gray_code_sequence.py)
* [Highest Set Bit](bit_manipulation/highest_set_bit.py)
* [Is Even](bit_manipulation/is_even.py) * [Is Even](bit_manipulation/is_even.py)
* [Reverse Bits](bit_manipulation/reverse_bits.py) * [Reverse Bits](bit_manipulation/reverse_bits.py)
* [Single Bit Manipulation Operations](bit_manipulation/single_bit_manipulation_operations.py) * [Single Bit Manipulation Operations](bit_manipulation/single_bit_manipulation_operations.py)
@ -326,6 +327,7 @@
## Financial ## Financial
* [Equated Monthly Installments](financial/equated_monthly_installments.py) * [Equated Monthly Installments](financial/equated_monthly_installments.py)
* [Interest](financial/interest.py) * [Interest](financial/interest.py)
* [Price Plus Tax](financial/price_plus_tax.py)
## Fractals ## Fractals
* [Julia Sets](fractals/julia_sets.py) * [Julia Sets](fractals/julia_sets.py)
@ -669,6 +671,7 @@
* [Horizontal Projectile Motion](physics/horizontal_projectile_motion.py) * [Horizontal Projectile Motion](physics/horizontal_projectile_motion.py)
* [Kinetic Energy](physics/kinetic_energy.py) * [Kinetic Energy](physics/kinetic_energy.py)
* [Lorentz Transformation Four Vector](physics/lorentz_transformation_four_vector.py) * [Lorentz Transformation Four Vector](physics/lorentz_transformation_four_vector.py)
* [Malus Law](physics/malus_law.py)
* [N Body Simulation](physics/n_body_simulation.py) * [N Body Simulation](physics/n_body_simulation.py)
* [Newtons Law Of Gravitation](physics/newtons_law_of_gravitation.py) * [Newtons Law Of Gravitation](physics/newtons_law_of_gravitation.py)
* [Newtons Second Law Of Motion](physics/newtons_second_law_of_motion.py) * [Newtons Second Law Of Motion](physics/newtons_second_law_of_motion.py)

View File

@ -86,8 +86,7 @@ def _validator(
""" """
# Checks if there are 3 unique rotors # Checks if there are 3 unique rotors
unique_rotsel = len(set(rotsel)) if (unique_rotsel := len(set(rotsel))) < 3:
if unique_rotsel < 3:
raise Exception(f"Please use 3 unique rotors (not {unique_rotsel})") raise Exception(f"Please use 3 unique rotors (not {unique_rotsel})")
# Checks if rotor positions are valid # Checks if rotor positions are valid

View File

@ -143,9 +143,8 @@ class LinkedList:
raise Exception("Node not found") raise Exception("Node not found")
def delete_value(self, value): def delete_value(self, value):
node = self.get_node(value)
if node is not None: if (node := self.get_node(value)) is not None:
if node == self.head: if node == self.head:
self.head = self.head.get_next() self.head = self.head.get_next()

View File

@ -18,8 +18,7 @@ class Fibonacci:
>>> Fibonacci().get(5) >>> Fibonacci().get(5)
[0, 1, 1, 2, 3] [0, 1, 1, 2, 3]
""" """
difference = index - (len(self.sequence) - 2) if (difference := index - (len(self.sequence) - 2)) >= 1:
if difference >= 1:
for _ in range(difference): for _ in range(difference):
self.sequence.append(self.sequence[-1] + self.sequence[-2]) self.sequence.append(self.sequence[-1] + self.sequence[-2])
return self.sequence[:index] return self.sequence[:index]

File diff suppressed because it is too large Load Diff

View File

@ -20,8 +20,7 @@ def indian_phone_validator(phone: str) -> bool:
True True
""" """
pat = re.compile(r"^(\+91[\-\s]?)?[0]?(91)?[789]\d{9}$") pat = re.compile(r"^(\+91[\-\s]?)?[0]?(91)?[789]\d{9}$")
match = re.search(pat, phone) if match := re.search(pat, phone):
if match:
return match.string == phone return match.string == phone
return False return False