dycw-utilities 0.109.12__py3-none-any.whl → 0.109.13__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dycw-utilities
3
- Version: 0.109.12
3
+ Version: 0.109.13
4
4
  Author-email: Derek Wan <d.wan@icloud.com>
5
5
  License-File: LICENSE
6
6
  Requires-Python: >=3.12
@@ -1,4 +1,4 @@
1
- utilities/__init__.py,sha256=V4hIkxHM85aC1wfztDqShV7oJrtyHnl9tBSs6Xoy5iM,61
1
+ utilities/__init__.py,sha256=8b_ivOe7dAl9N0yVvE9__TwO49X5ejp8NxQ28w6Xp0g,61
2
2
  utilities/altair.py,sha256=5WPwsHJoM-ZDh9iek4eSqf8_Ifb3w3KDwi7f2mrtXn4,9174
3
3
  utilities/astor.py,sha256=xuDUkjq0-b6fhtwjhbnebzbqQZAjMSHR1IIS5uOodVg,777
4
4
  utilities/asyncio.py,sha256=41oQUurWMvadFK5gFnaG21hMM0Vmfn2WS6OpC0R9mas,14757
@@ -26,7 +26,7 @@ utilities/hashlib.py,sha256=SVTgtguur0P4elppvzOBbLEjVM3Pea0eWB61yg2ilxo,309
26
26
  utilities/http.py,sha256=WcahTcKYRtZ04WXQoWt5EGCgFPcyHD3EJdlMfxvDt-0,946
27
27
  utilities/hypothesis.py,sha256=sLqYcrFn0I3o0R7maqliIERRtAcREk2CKG8rSHY1t5U,46205
28
28
  utilities/ipython.py,sha256=V2oMYHvEKvlNBzxDXdLvKi48oUq2SclRg5xasjaXStw,763
29
- utilities/iterables.py,sha256=AZSoLfHdttfdGx71s801YkkhoZ6s5RbJbTsjmf02Xjg,44381
29
+ utilities/iterables.py,sha256=GRuwMOPP7jqOnDdF113XYPjVg23VYn0ts1UlV-1Tzzo,45014
30
30
  utilities/jupyter.py,sha256=ft5JA7fBxXKzP-L9W8f2-wbF0QeYc_2uLQNFDVk4Z-M,2917
31
31
  utilities/logging.py,sha256=opIwFjGKOYyMntVeCsFNXOmTY2z02hMf2UtCB76SaI4,25142
32
32
  utilities/loguru.py,sha256=MEMQVWrdECxk1e3FxGzmOf21vWT9j8CAir98SEXFKPA,3809
@@ -85,7 +85,7 @@ utilities/warnings.py,sha256=yUgjnmkCRf6QhdyAXzl7u0qQFejhQG3PrjoSwxpbHrs,1819
85
85
  utilities/whenever.py,sha256=TjoTAJ1R27-rKXiXzdE4GzPidmYqm0W58XydDXp-QZM,17786
86
86
  utilities/zipfile.py,sha256=24lQc9ATcJxHXBPc_tBDiJk48pWyRrlxO2fIsFxU0A8,699
87
87
  utilities/zoneinfo.py,sha256=-DQz5a0Ikw9jfSZtL0BEQkXOMC9yGn_xiJYNCLMiqEc,1989
88
- dycw_utilities-0.109.12.dist-info/METADATA,sha256=zW9ZDqlnUhiKPhvPCB5I5C1Gs-dPC05fkGdFarYMcWM,13005
89
- dycw_utilities-0.109.12.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
90
- dycw_utilities-0.109.12.dist-info/licenses/LICENSE,sha256=gppZp16M6nSVpBbUBrNL6JuYfvKwZiKgV7XoKKsHzqo,1066
91
- dycw_utilities-0.109.12.dist-info/RECORD,,
88
+ dycw_utilities-0.109.13.dist-info/METADATA,sha256=7LZJJAQIYMDDVTGd220fgWLkFlrPCQQYDATGv4AnkeI,13005
89
+ dycw_utilities-0.109.13.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
90
+ dycw_utilities-0.109.13.dist-info/licenses/LICENSE,sha256=gppZp16M6nSVpBbUBrNL6JuYfvKwZiKgV7XoKKsHzqo,1066
91
+ dycw_utilities-0.109.13.dist-info/RECORD,,
utilities/__init__.py CHANGED
@@ -1,3 +1,3 @@
1
1
  from __future__ import annotations
2
2
 
3
- __version__ = "0.109.12"
3
+ __version__ = "0.109.13"
utilities/iterables.py CHANGED
@@ -19,7 +19,7 @@ from enum import Enum
19
19
  from functools import cmp_to_key, partial, reduce
20
20
  from itertools import accumulate, chain, groupby, islice, pairwise, product
21
21
  from math import isnan
22
- from operator import add, or_
22
+ from operator import add, itemgetter, or_
23
23
  from typing import (
24
24
  TYPE_CHECKING,
25
25
  Any,
@@ -861,6 +861,24 @@ def filter_include_and_exclude(
861
861
  ##
862
862
 
863
863
 
864
+ def group_consecutive_integers(iterable: Iterable[int], /) -> Iterable[tuple[int, int]]:
865
+ """Group consecutive integers."""
866
+ integers = sorted(iterable)
867
+ for _, group in groupby(enumerate(integers), key=lambda x: x[1] - x[0]):
868
+ as_list = list(map(itemgetter(1), group))
869
+ yield as_list[0], as_list[-1]
870
+
871
+
872
+ def ungroup_consecutive_integers(
873
+ iterable: Iterable[tuple[int, int]], /
874
+ ) -> Iterable[int]:
875
+ """Ungroup consecutive integers."""
876
+ return chain.from_iterable(range(start, end + 1) for start, end in iterable)
877
+
878
+
879
+ ##
880
+
881
+
864
882
  @overload
865
883
  def groupby_lists(
866
884
  iterable: Iterable[_T], /, *, key: None = None
@@ -1504,6 +1522,7 @@ __all__ = [
1504
1522
  "ensure_iterable_not_str",
1505
1523
  "expanding_window",
1506
1524
  "filter_include_and_exclude",
1525
+ "group_consecutive_integers",
1507
1526
  "groupby_lists",
1508
1527
  "hashable_to_iterable",
1509
1528
  "is_iterable",
@@ -1525,5 +1544,6 @@ __all__ = [
1525
1544
  "sum_mappings",
1526
1545
  "take",
1527
1546
  "transpose",
1547
+ "ungroup_consecutive_integers",
1528
1548
  "unique_everseen",
1529
1549
  ]