Skip to main contentIBM Quantum Documentation
Important

IBM Quantum Platform is moving and this version will be sunset on July 1. To get started on the new platform, read the migration guide.

Iteration utilities

qiskit_addon_cutting.utils.iteration

Iteration utilities.

unique_by_id

unique_by_id(iterable, /)

GitHub

Return unique objects in iterable, by identity.

>>> a = {0}
>>> list(unique_by_id([a, a]))
[{0}]
:rtype: :sphinx_autodoc_typehints_type:`\:py\:class\:\`\~collections.abc.ValuesView\``
>>> list(unique_by_id([a, a.copy()]))
[{0}, {0}]

Parameters

iterable (Iterable)

Return type

ValuesView

unique_by_eq

unique_by_eq(iterable, /)

GitHub

Return unique objects in iterable, by equality.

This function is only appropriate if (i) there are a small number of objects, and (ii) the objects are not guaranteed to be hashable. Otherwise, a dict or set is a better choice.

This function may potentially make a comparison between all pairs of elements, so it executes in O(n2)O(n^2) time in the worst case, in contrast to a dict or set, both of which can be constructed in O(n)O(n) time.

>>> a = {0}
>>> list(unique_by_eq([a, a]))
[{0}]
:rtype: :sphinx_autodoc_typehints_type:`\:py\:class\:\`list\``
>>> list(unique_by_eq([a, a.copy()]))
[{0}]

Parameters

iterable (Iterable)

Return type

list

Was this page helpful?
Report a bug or request content on GitHub.