lkj 0.1.44__py3-none-any.whl → 0.1.46__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.
lkj/strings.py CHANGED
@@ -741,7 +741,7 @@ def print_list(
741
741
  sep: str = ", ",
742
742
  line_prefix: str = "",
743
743
  items_per_line=None,
744
- show_count=True,
744
+ show_count: Union[bool, Callable[[int], str]] = False,
745
745
  title=None,
746
746
  print_func=print,
747
747
  ):
@@ -755,7 +755,7 @@ def print_list(
755
755
  sep: Separator for items
756
756
  line_prefix: Prefix for each line
757
757
  items_per_line: For columns style, how many items per line
758
- show_count: Whether to show the count of items
758
+ show_count: Whether to prefix with the count of items
759
759
  title: Optional title to display before the list
760
760
  print_func: Function to use for printing. Defaults to print.
761
761
  If None, returns the string instead of printing.
@@ -765,19 +765,16 @@ def print_list(
765
765
 
766
766
  # Wrapped style (default)
767
767
  >>> print_list(items, max_width=30)
768
- List (6 items):
769
768
  apple, banana, cherry, date,
770
769
  elderberry, fig
771
770
 
772
771
  # Columns style
773
772
  >>> print_list(items, style="columns", items_per_line=3)
774
- List (6 items):
775
773
  apple banana cherry
776
774
  date elderberry fig
777
775
 
778
776
  # Numbered style
779
777
  >>> print_list(items, style="numbered")
780
- List (6 items):
781
778
  1. apple
782
779
  2. banana
783
780
  3. cherry
@@ -787,7 +784,6 @@ def print_list(
787
784
 
788
785
  # Bullet style
789
786
  >>> print_list(items, style="bullet")
790
- List (6 items):
791
787
  • apple
792
788
  • banana
793
789
  • cherry
@@ -796,7 +792,7 @@ def print_list(
796
792
  • fig
797
793
 
798
794
  # Return string instead of printing
799
- >>> result = print_list(items, style="numbered", print_func=None)
795
+ >>> result = print_list(items, style="numbered", print_func=None, show_count=True)
800
796
  >>> print(result)
801
797
  List (6 items):
802
798
  1. apple
@@ -847,6 +843,8 @@ def print_list(
847
843
  print_func=print_func,
848
844
  )
849
845
  items = list(items) # Convert to list if it's an iterable
846
+ if show_count is True:
847
+ show_count = lambda n_items: f"List ({n_items} items):"
850
848
 
851
849
  # Handle print_func=None by using StringAppender
852
850
  if print_func is None:
@@ -860,7 +858,7 @@ def print_list(
860
858
  if title:
861
859
  print_func(title)
862
860
  elif show_count:
863
- print_func(f"List ({len(items)} items):")
861
+ print_func(show_count(len(items)))
864
862
 
865
863
  if not items:
866
864
  print_func(f"{line_prefix}(empty list)")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lkj
3
- Version: 0.1.44
3
+ Version: 0.1.46
4
4
  Summary: A dump of homeless useful utils
5
5
  Home-page: https://github.com/thorwhalen/lkj
6
6
  Author: Thor Whalen
@@ -167,3 +167,103 @@ import_object(dot_path: str)
167
167
  >>> f is join
168
168
  True
169
169
  ```
170
+
171
+ ## Pretty Printing Lists
172
+
173
+ The `print_list` function provides flexible, human-friendly ways to display lists and collections. It supports multiple display styles and can be used in several ways.
174
+
175
+ ### Basic Usage
176
+
177
+ ```python
178
+ from lkj.strings import print_list
179
+
180
+ items = ['apple', 'banana', 'cherry', 'date', 'elderberry', 'fig']
181
+
182
+ # Different display styles
183
+ print_list(items, style='wrapped') # Automatic line wrapping
184
+ print_list(items, style='columns') # Column format
185
+ print_list(items, style='numbered') # Numbered list
186
+ print_list(items, style='bullet') # Bullet points
187
+ print_list(items, style='compact') # All on one line
188
+ print_list(items, style='table') # Table format
189
+ ```
190
+
191
+ ### Direct Usage with Customization
192
+
193
+ ```python
194
+ # Customize width, separators, and formatting
195
+ print_list(items, style='wrapped', max_width=40, sep=' | ')
196
+ print_list(items, style='columns', items_per_line=3)
197
+ print_list(items, style='numbered', line_prefix=' ')
198
+ print_list(items, style='bullet', show_count=False)
199
+
200
+ # Return string instead of printing
201
+ result = print_list(items, style='numbered', print_func=None)
202
+ print(result)
203
+ ```
204
+
205
+ ### Partial Function Factory
206
+
207
+ When you don't specify the `items` parameter, `print_list` returns a partial function that you can reuse:
208
+
209
+ ```python
210
+ # Create specialized printers
211
+ numbered_printer = print_list(style='numbered', show_count=False)
212
+ bullet_printer = print_list(style='bullet', print_func=None)
213
+ compact_printer = print_list(style='compact', max_width=60)
214
+
215
+ # Reuse with different data
216
+ numbered_printer(['a', 'b', 'c']) # Prints: 1. a\n2. b\n3. c
217
+ result = bullet_printer(['x', 'y', 'z']) # Returns: '• x\n• y\n• z'
218
+ compact_printer(['item1', 'item2']) # Prints: item1, item2
219
+ ```
220
+
221
+ ### Convenience Methods
222
+
223
+ The `print_list` object provides convenient pre-configured methods:
224
+
225
+ ```python
226
+ # Quick access to common styles
227
+ print_list.compact(items) # Compact format, no count
228
+ print_list.wrapped(items) # Wrapped format, no count
229
+ print_list.columns(items) # Column format, no count
230
+ print_list.numbered(items) # Numbered format, no count
231
+ print_list.bullets(items) # Bullet format, no count
232
+
233
+ # Specialized methods
234
+ print_list.as_table(data) # Table with headers
235
+ print_list.summary(items) # Summary for long lists
236
+ ```
237
+
238
+ ### Advanced Examples
239
+
240
+ ```python
241
+ # Table with custom data
242
+ data = [['Name', 'Age', 'City'], ['Alice', 25, 'NYC'], ['Bob', 30, 'LA']]
243
+ print_list.as_table(data)
244
+
245
+ # Summary for long lists
246
+ long_list = list(range(100))
247
+ print_list.summary(long_list, max_items=6) # Shows: [0, 1, 2, ..., 97, 98, 99]
248
+
249
+ # Custom print function (e.g., for logging)
250
+ def my_logger(msg):
251
+ print(f"[LOG] {msg}")
252
+
253
+ print_list(items, style='bullet', print_func=my_logger)
254
+
255
+ # Combine partial with custom parameters
256
+ custom_compact = print_list(style='compact', sep=' | ')
257
+ custom_compact(items) # Prints: apple | banana | cherry | date | elderberry | fig
258
+ ```
259
+
260
+ ### Key Features
261
+
262
+ - **Multiple Styles**: `wrapped`, `columns`, `numbered`, `bullet`, `compact`, `table`
263
+ - **Flexible Output**: Print directly or return strings with `print_func=None`
264
+ - **Partial Functions**: Create reusable printers with pre-configured settings
265
+ - **Customizable**: Control width, separators, line prefixes, and more
266
+ - **Type Safe**: Uses `Literal` types for style validation
267
+ - **Self-Contained**: No external dependencies beyond Python standard library
268
+
269
+ The `print_list` function is perfect for debugging, logging, user interfaces, and any situation where you need to display lists in a readable format.
@@ -7,9 +7,9 @@ lkj/importing.py,sha256=TcW3qUDmw7jqswpxXnksjlHkkbOJq70NbUk1ZyaafT0,6658
7
7
  lkj/iterables.py,sha256=9jeO36w-IGiZryge7JKgXZOGZAgehUvhwKV3nHPcZWk,2801
8
8
  lkj/loggers.py,sha256=ImmBdacz89Lvb3dg_xI5jOct_44rSRv0hNI_CVehy60,13706
9
9
  lkj/misc.py,sha256=IZf05tkl0cgiMgBwCMH5cLSC59fRXwnemPRo8G0OxQg,1436
10
- lkj/strings.py,sha256=aib3KLFBuHl2WuDI2m7xC2JXM9E2-fk9CkXU7Pld6VU,41459
11
- lkj-0.1.44.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
12
- lkj-0.1.44.dist-info/METADATA,sha256=UIL9HF85Q1yjtn_UCjmh7LYpRv_XDEJHvVZQUlWGm84,4684
13
- lkj-0.1.44.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
14
- lkj-0.1.44.dist-info/top_level.txt,sha256=3DZOUwYmyurJFBXQCvCmEIVm8z2b42O5Sx3RDQyePfg,4
15
- lkj-0.1.44.dist-info/RECORD,,
10
+ lkj/strings.py,sha256=J3MD8sbXoaV7uACtue5v9QhAhFLjUCksf-cCTf9Ez5o,41509
11
+ lkj-0.1.46.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
12
+ lkj-0.1.46.dist-info/METADATA,sha256=Q7e2mCXrROS5o5HcDNEnsJO3WZQnW-AnR2-0eiOKLfY,8221
13
+ lkj-0.1.46.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
14
+ lkj-0.1.46.dist-info/top_level.txt,sha256=3DZOUwYmyurJFBXQCvCmEIVm8z2b42O5Sx3RDQyePfg,4
15
+ lkj-0.1.46.dist-info/RECORD,,
File without changes
File without changes