deep-sort-list-parser 1.0.0__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.
deep_sort_list.py ADDED
@@ -0,0 +1,83 @@
1
+ def clean_and_flatten(any_input, convert_numeric_strings = False):
2
+ """
3
+ Flattens any list and returns a DICTIONARY of sorted tracks.
4
+ If convert_numeric_strings is True, text like '100' becomes an integer.
5
+ """
6
+ numbers = []
7
+ words = []
8
+ symbols = []
9
+
10
+ dict_tracks = []
11
+
12
+ # THE FIX FOR ACCIDENTAL INPUTS:
13
+ # If the user passed a single item (not a list and not a dict),
14
+ # wrap it inside a list box automatically so the loop doesn't crash!
15
+
16
+ if type(any_input) is list:
17
+ any_list = any_input
18
+ else:
19
+ any_list = [any_input]
20
+
21
+ def unpack(box):
22
+
23
+ for item in box:
24
+ if type(item) is list:
25
+ unpack(item)
26
+
27
+ # Find any dictionary inside the list box
28
+ elif type(item) is dict:
29
+ def deep_sort_dict(input_dict):
30
+ """
31
+ Takes any dictionary, sorts its keys alphabetically,
32
+ and checks if any of its values are ALSO dictionaries to sort them too!
33
+ """
34
+ sorted_dict = {}
35
+
36
+ sorted_keys = sorted(input_dict.keys(), key=str) # Grab all keys and sort them alphabetically
37
+
38
+ for key in sorted_keys:
39
+ value = input_dict[key]
40
+
41
+ # RECURSION CHECK: If the value inside this key is ANOTHER dictionary,call deep_sort_dict
42
+ if type(value) is dict:
43
+ sorted_dict[key] = deep_sort_dict(value)
44
+ else:
45
+ sorted_dict[key] = value
46
+
47
+ return sorted_dict
48
+ clean_dict = deep_sort_dict(item)
49
+ dict_tracks.append(clean_dict)
50
+
51
+ elif type(item) in (int, float, bool):
52
+ numbers.append(item)
53
+ else:
54
+ text_item = str(item)
55
+
56
+ if text_item.isalnum() == False: # Check for special characters first
57
+ symbols.append(text_item)
58
+ else:
59
+ # User requirement check: Should we turn string numbers into integers?
60
+ if convert_numeric_strings and text_item.isdigit():
61
+ numbers.append(int(text_item))
62
+ else:
63
+ words.append(text_item)
64
+
65
+ # Start the engine using the dynamic argument variable
66
+ unpack(any_list)
67
+
68
+
69
+ # Sort each individual track cleanly
70
+ numbers.sort()
71
+ words.sort()
72
+ symbols.sort()
73
+
74
+ # RETURN A DICTIONARY: This hands the clean data back to the user!
75
+
76
+ return {
77
+ "numbers": numbers,
78
+ "symbols": symbols,
79
+ "words": words,
80
+ "dictionaries": dict_tracks
81
+ }
82
+
83
+
@@ -0,0 +1,8 @@
1
+ Metadata-Version: 2.4
2
+ Name: deep_sort_list_parser
3
+ Version: 1.0.0
4
+ Summary: A recursive data parser to flatten and sort complex nested structures safely.
5
+ Author: Developer
6
+ Classifier: License :: OSI Approved :: MIT License
7
+ Classifier: Programming Language :: Python :: 3
8
+ Requires-Python: >=3.8
@@ -0,0 +1,4 @@
1
+ deep_sort_list.py,sha256=HD-z4MPM75j-4P8SkhqxxUH2wWs0FA-u8Zpx_xzC1wE,2968
2
+ deep_sort_list_parser-1.0.0.dist-info/METADATA,sha256=Ojmk25lTXyZROMjlqJ--8CxByYBInO7ezKGToEqdDeE,292
3
+ deep_sort_list_parser-1.0.0.dist-info/WHEEL,sha256=lCkmxWfQsSc9CfIClYeavTdQeEX2toPqufh9gI35EQA,87
4
+ deep_sort_list_parser-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.31.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any