Skip to content

Commit

Permalink
Move inline _flatten to top of qubit_set.py (#691)
Browse files Browse the repository at this point in the history
  • Loading branch information
speller26 authored Aug 28, 2023
1 parent 45b3884 commit 0dcbd70
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/braket/circuits/qubit_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@
QubitSetInput = Union[QubitInput, Iterable[QubitInput]]


def _flatten(other: Any) -> Any:
if isinstance(other, Iterable) and not isinstance(other, str):
for item in other:
yield from _flatten(item)
else:
yield other


class QubitSet(IndexedSet):
"""
An ordered, unique set of quantum bits.
Expand Down Expand Up @@ -54,13 +62,6 @@ def __init__(self, qubits: QubitSetInput = None):
Qubit(3)
"""

def _flatten(other: Any) -> Any:
if isinstance(other, Iterable) and not isinstance(other, str):
for item in other:
yield from _flatten(item)
else:
yield other

_qubits = [Qubit.new(qubit) for qubit in _flatten(qubits)] if qubits is not None else None
super().__init__(_qubits)

Expand Down

0 comments on commit 0dcbd70

Please sign in to comment.