From 36691fadf8da83aef8e9037333d892b1201c043a Mon Sep 17 00:00:00 2001 From: denpamusic Date: Tue, 24 Oct 2023 04:20:42 +0300 Subject: [PATCH] Simplify join bits function. Use reduce from itertools instead of for. --- pyplumio/structures/schedules.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/pyplumio/structures/schedules.py b/pyplumio/structures/schedules.py index 5cf18c1c..d3ab96bc 100644 --- a/pyplumio/structures/schedules.py +++ b/pyplumio/structures/schedules.py @@ -3,6 +3,7 @@ from collections.abc import Sequence from dataclasses import dataclass +from functools import reduce from itertools import chain from typing import TYPE_CHECKING, Final @@ -135,11 +136,7 @@ def _split_byte(byte: int) -> list[bool]: def _join_bits(bits: Sequence[int | bool]) -> int: """Join eight bits into a single byte.""" - result = 0 - for bit in bits: - result = (result << 1) | bit - - return result + return reduce(lambda x, y: (x << 1) | y, bits) class SchedulesStructure(Structure):