deep-sort-list-parser 1.0.6__tar.gz → 1.0.7__tar.gz
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_parser-1.0.7/PKG-INFO +65 -0
- deep_sort_list_parser-1.0.7/README.md +53 -0
- deep_sort_list_parser-1.0.7/deep_sort_list.py +107 -0
- deep_sort_list_parser-1.0.7/pyproject.toml +33 -0
- deep_sort_list_parser-1.0.6/PKG-INFO +0 -66
- deep_sort_list_parser-1.0.6/README.md +0 -56
- deep_sort_list_parser-1.0.6/deep_sort_list.py +0 -114
- deep_sort_list_parser-1.0.6/deep_sort_list_test.py +0 -39
- deep_sort_list_parser-1.0.6/pyproject.toml +0 -24
- deep_sort_list_parser-1.0.6/test_suite.py +0 -27
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: deep_sort_list_parser
|
|
3
|
+
Version: 1.0.7
|
|
4
|
+
Summary: An iterative, dual-stack nested collection flattener and type-safe data parsing sorting tool.
|
|
5
|
+
Project-URL: Homepage, https://github.com/08singhShreya/deep_sort_list
|
|
6
|
+
Author-email: Shreya Singh <09shreyasingh99@gmail.com>
|
|
7
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
8
|
+
Classifier: Operating System :: OS Independent
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Requires-Python: >=3.7
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
|
|
13
|
+
# 📦 deep_sort_list_parser
|
|
14
|
+
|
|
15
|
+
A lightweight, bulletproof utility library to flatten and sort mixed data arrays (Lists, Tuples, Sets, and Dictionaries) without crashing.
|
|
16
|
+
|
|
17
|
+
It handles everything inside a single loop stack, meaning it will never crash from memory limits even if your data is nested thousands of layers deep.
|
|
18
|
+
|
|
19
|
+
## ✨ Key Features
|
|
20
|
+
- **Infinite Flattening:** Automatically drills through nested layers like `[[[]]]` to pull out elements.
|
|
21
|
+
- **Type-Safe Tracking:** Splits data into four clean, sorted tracks: Numbers, Words, Symbols, and Dictionaries.
|
|
22
|
+
- **Boolean Safe:** Keeps `True` / `False` inside the words track so they don't break your mathematical number sorting.
|
|
23
|
+
- **Locker Key Sorting:** Alphabetizes keys inside nested dictionaries down to any depth without losing their original key-value pairs.
|
|
24
|
+
- **String-to-Int Conversion:** Optional flag converts numeric text like `'100'` into real integers on command.
|
|
25
|
+
|
|
26
|
+
## 🚀 How to Use
|
|
27
|
+
|
|
28
|
+
### 🔹 Example 1: Standard Mixed Input (With Sentences & Booleans)
|
|
29
|
+
```python
|
|
30
|
+
import deep_sort_list
|
|
31
|
+
|
|
32
|
+
data = [44, [3, "banana!"], "Hello World", True]
|
|
33
|
+
result = deep_sort_list.clean_and_flatten(data)
|
|
34
|
+
|
|
35
|
+
print(result["numbers"]) # [3, 44]
|
|
36
|
+
print(result["words"]) # ['Hello World', 'True', 'banana!']
|
|
37
|
+
print(result["symbols"]) # []
|
|
38
|
+
print(result["dictionaries"]) # []
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### 🔹 Example 2: Handling Nested Dictionaries
|
|
42
|
+
```python
|
|
43
|
+
nested_data = [{"sex": "Female", "name": "Shreya"}]
|
|
44
|
+
result = deep_sort_list.clean_and_flatten(nested_data)
|
|
45
|
+
|
|
46
|
+
print(result["dictionaries"])
|
|
47
|
+
# Output: [{'name': 'Shreya', 'sex': 'Female'}]
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### 🔹 Example 3: String Number Conversion ON
|
|
51
|
+
```python
|
|
52
|
+
data = [44, "100", "banana"]
|
|
53
|
+
# Set convert_numeric_strings to True to change text digits into real math integers
|
|
54
|
+
result = deep_sort_list.clean_and_flatten(data, convert_numeric_strings=True)
|
|
55
|
+
|
|
56
|
+
print(result["numbers"]) # [44, 100]
|
|
57
|
+
print(result["words"]) # ['banana']
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## 📊 Output Schema Layout
|
|
61
|
+
The library always returns a standard dictionary map containing:
|
|
62
|
+
- `result["numbers"]`: Perfectly sorted integers and floats.
|
|
63
|
+
- `result["words"]`: Perfectly sorted alphanumeric words, sentences, and booleans.
|
|
64
|
+
- `result["symbols"]`: Perfectly sorted pure punctuation strings (like `@`, `#`, `^`).
|
|
65
|
+
- `result["dictionaries"]`: Isolated dictionary blocks with internal alphabetical keys.
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# 📦 deep_sort_list_parser
|
|
2
|
+
|
|
3
|
+
A lightweight, bulletproof utility library to flatten and sort mixed data arrays (Lists, Tuples, Sets, and Dictionaries) without crashing.
|
|
4
|
+
|
|
5
|
+
It handles everything inside a single loop stack, meaning it will never crash from memory limits even if your data is nested thousands of layers deep.
|
|
6
|
+
|
|
7
|
+
## ✨ Key Features
|
|
8
|
+
- **Infinite Flattening:** Automatically drills through nested layers like `[[[]]]` to pull out elements.
|
|
9
|
+
- **Type-Safe Tracking:** Splits data into four clean, sorted tracks: Numbers, Words, Symbols, and Dictionaries.
|
|
10
|
+
- **Boolean Safe:** Keeps `True` / `False` inside the words track so they don't break your mathematical number sorting.
|
|
11
|
+
- **Locker Key Sorting:** Alphabetizes keys inside nested dictionaries down to any depth without losing their original key-value pairs.
|
|
12
|
+
- **String-to-Int Conversion:** Optional flag converts numeric text like `'100'` into real integers on command.
|
|
13
|
+
|
|
14
|
+
## 🚀 How to Use
|
|
15
|
+
|
|
16
|
+
### 🔹 Example 1: Standard Mixed Input (With Sentences & Booleans)
|
|
17
|
+
```python
|
|
18
|
+
import deep_sort_list
|
|
19
|
+
|
|
20
|
+
data = [44, [3, "banana!"], "Hello World", True]
|
|
21
|
+
result = deep_sort_list.clean_and_flatten(data)
|
|
22
|
+
|
|
23
|
+
print(result["numbers"]) # [3, 44]
|
|
24
|
+
print(result["words"]) # ['Hello World', 'True', 'banana!']
|
|
25
|
+
print(result["symbols"]) # []
|
|
26
|
+
print(result["dictionaries"]) # []
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### 🔹 Example 2: Handling Nested Dictionaries
|
|
30
|
+
```python
|
|
31
|
+
nested_data = [{"sex": "Female", "name": "Shreya"}]
|
|
32
|
+
result = deep_sort_list.clean_and_flatten(nested_data)
|
|
33
|
+
|
|
34
|
+
print(result["dictionaries"])
|
|
35
|
+
# Output: [{'name': 'Shreya', 'sex': 'Female'}]
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### 🔹 Example 3: String Number Conversion ON
|
|
39
|
+
```python
|
|
40
|
+
data = [44, "100", "banana"]
|
|
41
|
+
# Set convert_numeric_strings to True to change text digits into real math integers
|
|
42
|
+
result = deep_sort_list.clean_and_flatten(data, convert_numeric_strings=True)
|
|
43
|
+
|
|
44
|
+
print(result["numbers"]) # [44, 100]
|
|
45
|
+
print(result["words"]) # ['banana']
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## 📊 Output Schema Layout
|
|
49
|
+
The library always returns a standard dictionary map containing:
|
|
50
|
+
- `result["numbers"]`: Perfectly sorted integers and floats.
|
|
51
|
+
- `result["words"]`: Perfectly sorted alphanumeric words, sentences, and booleans.
|
|
52
|
+
- `result["symbols"]`: Perfectly sorted pure punctuation strings (like `@`, `#`, `^`).
|
|
53
|
+
- `result["dictionaries"]`: Isolated dictionary blocks with internal alphabetical keys.
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import collections
|
|
2
|
+
|
|
3
|
+
def deep_sort_dict(input_dict):
|
|
4
|
+
"""
|
|
5
|
+
Safely sorts dictionary keys alphabetically using an iterative stack approach
|
|
6
|
+
to avoid any recursive stack depth limitations.
|
|
7
|
+
"""
|
|
8
|
+
root_sorted = {}
|
|
9
|
+
stack = [(input_dict, root_sorted)]
|
|
10
|
+
|
|
11
|
+
while stack:
|
|
12
|
+
|
|
13
|
+
curr_dict, target_dict = stack.pop()
|
|
14
|
+
|
|
15
|
+
sorted_keys = sorted(curr_dict.keys(), key=str)
|
|
16
|
+
|
|
17
|
+
for key in sorted_keys:
|
|
18
|
+
value = curr_dict[key]
|
|
19
|
+
|
|
20
|
+
# Use isinstance to support OrderedDict, Counter, and sub-dicts
|
|
21
|
+
|
|
22
|
+
if isinstance(value, dict): # Create the nested skeleton and push it to our work stack
|
|
23
|
+
target_dict[key] = {}
|
|
24
|
+
stack.append((value, target_dict[key]))
|
|
25
|
+
else:
|
|
26
|
+
target_dict[key] = value
|
|
27
|
+
return root_sorted
|
|
28
|
+
|
|
29
|
+
def clean_and_flatten(any_input, convert_numeric_strings = False):
|
|
30
|
+
"""
|
|
31
|
+
Iteratively flattens nested data structures and segregates types into sorted streams.
|
|
32
|
+
Bypasses Python's 1000 recursion limit using a manual array processing stack.
|
|
33
|
+
"""
|
|
34
|
+
numbers = []
|
|
35
|
+
words = []
|
|
36
|
+
symbols = []
|
|
37
|
+
dict_tracks = []
|
|
38
|
+
|
|
39
|
+
# Normalization: Force structural wrappers.
|
|
40
|
+
|
|
41
|
+
if isinstance(any_input, (list, tuple)):
|
|
42
|
+
# We make a shallow copy or cast to a list so we can freely mutate our working stack
|
|
43
|
+
processing_stack = list(any_input)
|
|
44
|
+
elif isinstance(any_input, set):
|
|
45
|
+
processing_stack = list(any_input)
|
|
46
|
+
else:
|
|
47
|
+
processing_stack = [any_input]
|
|
48
|
+
|
|
49
|
+
# Reverse to maintain original left-to-right processing order since we pop from the end
|
|
50
|
+
processing_stack.reverse()
|
|
51
|
+
|
|
52
|
+
while processing_stack:
|
|
53
|
+
item = processing_stack.pop()
|
|
54
|
+
|
|
55
|
+
# Scenario A: Nested containers (Lists, Tuples, Sets)
|
|
56
|
+
if isinstance(item, (list, tuple, set)):
|
|
57
|
+
# Convert to list and extend backwards onto the stack to keep structural alignment
|
|
58
|
+
inner_items = list(item)
|
|
59
|
+
inner_items.reverse()
|
|
60
|
+
processing_stack.extend(inner_items)
|
|
61
|
+
|
|
62
|
+
# Scenario B: Dictionaries
|
|
63
|
+
elif isinstance(item, dict):
|
|
64
|
+
clean_dict = deep_sort_dict(item) #call global_helper_function
|
|
65
|
+
dict_tracks.append(clean_dict)
|
|
66
|
+
|
|
67
|
+
# Scenario C: True Booleans
|
|
68
|
+
elif type(item) is bool:
|
|
69
|
+
if item is True:
|
|
70
|
+
words.append("True")
|
|
71
|
+
else:
|
|
72
|
+
words.append("False")
|
|
73
|
+
|
|
74
|
+
# Scenario D: Numbers
|
|
75
|
+
elif isinstance(item, (int, float)):
|
|
76
|
+
numbers.append(item)
|
|
77
|
+
|
|
78
|
+
# Scenario E: Strings and Custom Type fallbacks
|
|
79
|
+
else:
|
|
80
|
+
text_item = str(item)
|
|
81
|
+
|
|
82
|
+
# Smart word evaluation check.
|
|
83
|
+
# If a string has letters or digits (even with spaces/exclamations), it's a word track item.
|
|
84
|
+
# If it is only pure punctuation characters (like "@@@"), it goes to symbols.
|
|
85
|
+
|
|
86
|
+
if any(char.isalnum() for char in text_item):
|
|
87
|
+
if convert_numeric_strings and text_item.isdigit():
|
|
88
|
+
numbers.append(int(text_item))
|
|
89
|
+
else:
|
|
90
|
+
words.append(text_item)
|
|
91
|
+
|
|
92
|
+
else:
|
|
93
|
+
symbols.append(text_item)
|
|
94
|
+
|
|
95
|
+
# Sort each individual track cleanly
|
|
96
|
+
numbers.sort()
|
|
97
|
+
words.sort()
|
|
98
|
+
symbols.sort()
|
|
99
|
+
|
|
100
|
+
return {
|
|
101
|
+
"numbers": numbers,
|
|
102
|
+
"symbols": symbols,
|
|
103
|
+
"words": words,
|
|
104
|
+
"dictionaries": dict_tracks
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "deep_sort_list_parser"
|
|
7
|
+
version = "1.0.7"
|
|
8
|
+
authors = [
|
|
9
|
+
{ name="Shreya Singh", email="09shreyasingh99@gmail.com" },
|
|
10
|
+
]
|
|
11
|
+
description = "An iterative, dual-stack nested collection flattener and type-safe data parsing sorting tool."
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
requires-python = ">=3.7"
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"License :: OSI Approved :: MIT License",
|
|
17
|
+
"Operating System :: OS Independent",
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
[project.urls]
|
|
21
|
+
Homepage = "https://github.com/08singhShreya/deep_sort_list"
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
[tool.hatch.build.targets.wheel]
|
|
25
|
+
only-include = ["deep_sort_list.py"]
|
|
26
|
+
|
|
27
|
+
[tool.hatch.build.targets.sdist]
|
|
28
|
+
only-include = ["deep_sort_list.py", "README.md", "pyproject.toml"]
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: deep_sort_list_parser
|
|
3
|
-
Version: 1.0.6
|
|
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
|
|
9
|
-
Description-Content-Type: text/markdown
|
|
10
|
-
|
|
11
|
-
# 📦 deep_sort_list_parser
|
|
12
|
-
|
|
13
|
-
A data parsing library designed to safely unwrap, flatten, and sort messy, multi-nested collections (Lists, Tuples, Sets, and Dictionaries) without crashing.
|
|
14
|
-
|
|
15
|
-
## 🌟 Enhanced Features
|
|
16
|
-
- **Infinite Flattening:** Recursively drills through any number of nested list layouts `[[[]]]` to extract loose data.
|
|
17
|
-
- **Advanced Type-Safe Tracking:** Automatically isolates items into distinct sorted categories: Numbers, Words, and Symbols.
|
|
18
|
-
- **Smart Text Analysis:** Intelligently tracks sentences with spaces and punctuation (like `"Hello World!"`) inside the words track instead of breaking them apart.
|
|
19
|
-
- **Boolean Guarding:** Standard booleans (`True` / `False`) are trapped safely and sorted inside the words track instead of corrupting mathematical numbers.
|
|
20
|
-
- **Deep Locker Sorting:** Alphabetizes keys inside nested dictionaries down to any depth while keeping values safely paired. Fully supports specialized dictionaries like `OrderedDict` and `Counter`.
|
|
21
|
-
- **On-the-Fly Conversion:** Dynamically casts numeric text strings (like `'100'`) into math integers upon request.
|
|
22
|
-
|
|
23
|
-
## 🚀 How to Use
|
|
24
|
-
|
|
25
|
-
Save `deep_sort_list.py` in your project folder, import it, and pass your data payload into the `clean_and_flatten` function.
|
|
26
|
-
|
|
27
|
-
### 🔹 Scenario 1: Standard Mixed Input (With Sentences & Booleans)
|
|
28
|
-
You can pass completely mixed lists, nested containers, or even single loose items safely.
|
|
29
|
-
|
|
30
|
-
```python
|
|
31
|
-
import deep_sort_list
|
|
32
|
-
|
|
33
|
-
# A chaotic list containing numbers, strings with punctuation, and booleans
|
|
34
|
-
data = [44, [3, "@#%&"], "Hello World!", True]
|
|
35
|
-
|
|
36
|
-
result = deep_sort_list.clean_and_flatten(data)
|
|
37
|
-
|
|
38
|
-
print(result["numbers"]) # [3, 44]
|
|
39
|
-
print(result["words"]) # ['Hello World!', 'True']
|
|
40
|
-
print(result["symbols"]) # ['@#%&']
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
### 🔹 Scenario 2: Handling Nested Dictionaries (Locker Sorting)
|
|
44
|
-
If your input contains complex dictionary blocks, the engine alphabetizes all internal keys at every sub-layer while keeping values locked to their pairs.
|
|
45
|
-
|
|
46
|
-
```python
|
|
47
|
-
nested_data = [{"sex": "Female", "name": {"last": "Singh", "first": "Aadhya"}}]
|
|
48
|
-
|
|
49
|
-
result = deep_sort_list.clean_and_flatten(nested_data)
|
|
50
|
-
print(result["dictionaries"])
|
|
51
|
-
# Output: [{'name': {'first': 'Aadhya', 'last': 'Singh'}, 'sex': 'Female'}]
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
### 🔹 Scenario 3: Smart Number Conversion
|
|
55
|
-
By default, text digits like `'100'` are kept in the words track. Set `convert_numeric_strings=True` to dynamically convert and sort them as math integers.
|
|
56
|
-
|
|
57
|
-
```python
|
|
58
|
-
result = deep_sort_list.clean_and_flatten(data, convert_numeric_strings=True)
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
## 📊 Return Format
|
|
62
|
-
The function returns a clean Python dictionary with four distinct tracks:
|
|
63
|
-
- `result["numbers"]`: Sorted integers and floats.
|
|
64
|
-
- `result["words"]`: Sorted alphanumeric text words, sentences, and booleans.
|
|
65
|
-
- `result["symbols"]`: Sorted pure punctuation strings (like `@`, `#`, `^`).
|
|
66
|
-
- `result["dictionaries"]`: Isolated dictionary blocks with fully alphabetized internal key layouts.
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
# 📦 deep_sort_list_parser
|
|
2
|
-
|
|
3
|
-
A data parsing library designed to safely unwrap, flatten, and sort messy, multi-nested collections (Lists, Tuples, Sets, and Dictionaries) without crashing.
|
|
4
|
-
|
|
5
|
-
## 🌟 Enhanced Features
|
|
6
|
-
- **Infinite Flattening:** Recursively drills through any number of nested list layouts `[[[]]]` to extract loose data.
|
|
7
|
-
- **Advanced Type-Safe Tracking:** Automatically isolates items into distinct sorted categories: Numbers, Words, and Symbols.
|
|
8
|
-
- **Smart Text Analysis:** Intelligently tracks sentences with spaces and punctuation (like `"Hello World!"`) inside the words track instead of breaking them apart.
|
|
9
|
-
- **Boolean Guarding:** Standard booleans (`True` / `False`) are trapped safely and sorted inside the words track instead of corrupting mathematical numbers.
|
|
10
|
-
- **Deep Locker Sorting:** Alphabetizes keys inside nested dictionaries down to any depth while keeping values safely paired. Fully supports specialized dictionaries like `OrderedDict` and `Counter`.
|
|
11
|
-
- **On-the-Fly Conversion:** Dynamically casts numeric text strings (like `'100'`) into math integers upon request.
|
|
12
|
-
|
|
13
|
-
## 🚀 How to Use
|
|
14
|
-
|
|
15
|
-
Save `deep_sort_list.py` in your project folder, import it, and pass your data payload into the `clean_and_flatten` function.
|
|
16
|
-
|
|
17
|
-
### 🔹 Scenario 1: Standard Mixed Input (With Sentences & Booleans)
|
|
18
|
-
You can pass completely mixed lists, nested containers, or even single loose items safely.
|
|
19
|
-
|
|
20
|
-
```python
|
|
21
|
-
import deep_sort_list
|
|
22
|
-
|
|
23
|
-
# A chaotic list containing numbers, strings with punctuation, and booleans
|
|
24
|
-
data = [44, [3, "@#%&"], "Hello World!", True]
|
|
25
|
-
|
|
26
|
-
result = deep_sort_list.clean_and_flatten(data)
|
|
27
|
-
|
|
28
|
-
print(result["numbers"]) # [3, 44]
|
|
29
|
-
print(result["words"]) # ['Hello World!', 'True']
|
|
30
|
-
print(result["symbols"]) # ['@#%&']
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
### 🔹 Scenario 2: Handling Nested Dictionaries (Locker Sorting)
|
|
34
|
-
If your input contains complex dictionary blocks, the engine alphabetizes all internal keys at every sub-layer while keeping values locked to their pairs.
|
|
35
|
-
|
|
36
|
-
```python
|
|
37
|
-
nested_data = [{"sex": "Female", "name": {"last": "Singh", "first": "Aadhya"}}]
|
|
38
|
-
|
|
39
|
-
result = deep_sort_list.clean_and_flatten(nested_data)
|
|
40
|
-
print(result["dictionaries"])
|
|
41
|
-
# Output: [{'name': {'first': 'Aadhya', 'last': 'Singh'}, 'sex': 'Female'}]
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
### 🔹 Scenario 3: Smart Number Conversion
|
|
45
|
-
By default, text digits like `'100'` are kept in the words track. Set `convert_numeric_strings=True` to dynamically convert and sort them as math integers.
|
|
46
|
-
|
|
47
|
-
```python
|
|
48
|
-
result = deep_sort_list.clean_and_flatten(data, convert_numeric_strings=True)
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
## 📊 Return Format
|
|
52
|
-
The function returns a clean Python dictionary with four distinct tracks:
|
|
53
|
-
- `result["numbers"]`: Sorted integers and floats.
|
|
54
|
-
- `result["words"]`: Sorted alphanumeric text words, sentences, and booleans.
|
|
55
|
-
- `result["symbols"]`: Sorted pure punctuation strings (like `@`, `#`, `^`).
|
|
56
|
-
- `result["dictionaries"]`: Isolated dictionary blocks with fully alphabetized internal key layouts.
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import collections
|
|
2
|
-
|
|
3
|
-
def deep_sort_dict(input_dict):
|
|
4
|
-
"""
|
|
5
|
-
Takes any dictionary, sorts its keys alphabetically,
|
|
6
|
-
and checks if any of its values are ALSO dictionaries to sort them too!
|
|
7
|
-
"""
|
|
8
|
-
sorted_dict = {}
|
|
9
|
-
sorted_keys = sorted(input_dict.keys(), key=str)
|
|
10
|
-
|
|
11
|
-
for key in sorted_keys:
|
|
12
|
-
value = input_dict[key]
|
|
13
|
-
|
|
14
|
-
# Use isinstance to support OrderedDict, Counter, and sub-dicts
|
|
15
|
-
|
|
16
|
-
if isinstance(value, dict): # RECURSION CHECK: If the value inside this key is ANOTHER dictionary,call deep_sort_dict
|
|
17
|
-
sorted_dict[key] = deep_sort_dict(value)
|
|
18
|
-
else:
|
|
19
|
-
sorted_dict[key] = value
|
|
20
|
-
return sorted_dict
|
|
21
|
-
|
|
22
|
-
def clean_and_flatten(any_input, convert_numeric_strings = False):
|
|
23
|
-
"""
|
|
24
|
-
Recursively flattens nested data structures and segregates types into sorted streams.
|
|
25
|
-
|
|
26
|
-
This function drills down into infinitely nested lists, tuples, sets, and
|
|
27
|
-
dictionaries. It separates loose elements into type-safe buckets, safely
|
|
28
|
-
alphabetizes internal dictionary configurations without losing key-value mappings,
|
|
29
|
-
and handles booleans and complex strings without pipeline crashes.
|
|
30
|
-
|
|
31
|
-
Parameters:
|
|
32
|
-
-----------
|
|
33
|
-
any_input : any
|
|
34
|
-
The entry-level data element or container (list, tuple, set, dict,
|
|
35
|
-
int, float, bool, or str) to parse.
|
|
36
|
-
convert_numeric_strings : bool, default False
|
|
37
|
-
If True, text strings containing pure digits (e.g., '100') will be
|
|
38
|
-
dynamically converted into integers and sorted into the numbers track.
|
|
39
|
-
|
|
40
|
-
Returns:
|
|
41
|
-
--------
|
|
42
|
-
dict
|
|
43
|
-
A structured dictionary map holding four cleanly sorted data streams:
|
|
44
|
-
- "numbers": Sorted integers and floats.
|
|
45
|
-
- "symbols": Sorted pure punctuation marks.
|
|
46
|
-
- "words": Sorted alphanumeric text strings and standalone booleans.
|
|
47
|
-
- "dictionaries": Sorted dictionaries with internal alphabetical keys.
|
|
48
|
-
"""
|
|
49
|
-
numbers = []
|
|
50
|
-
words = []
|
|
51
|
-
symbols = []
|
|
52
|
-
dict_tracks = []
|
|
53
|
-
|
|
54
|
-
# HANDLE ACCIDENTAL INPUTS at entry level:
|
|
55
|
-
# Supports custom lists/tuples/sets safely via Sequence checks
|
|
56
|
-
|
|
57
|
-
if isinstance(any_input, (list, tuple, set)):
|
|
58
|
-
any_list = any_input
|
|
59
|
-
else:
|
|
60
|
-
any_list = [any_input]
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
def unpack(box):
|
|
64
|
-
for item in box:
|
|
65
|
-
if isinstance(item, (list, tuple, set)):
|
|
66
|
-
unpack(item)
|
|
67
|
-
|
|
68
|
-
# Find any dictionary inside the list box
|
|
69
|
-
elif isinstance(item, dict):
|
|
70
|
-
clean_dict = deep_sort_dict(item) #call global_helper_function
|
|
71
|
-
dict_tracks.append(clean_dict)
|
|
72
|
-
|
|
73
|
-
elif type(item) is bool:
|
|
74
|
-
if item is True:
|
|
75
|
-
words.append("True")
|
|
76
|
-
else:
|
|
77
|
-
words.append("False")
|
|
78
|
-
|
|
79
|
-
elif isinstance(item, (int, float)):
|
|
80
|
-
numbers.append(item)
|
|
81
|
-
|
|
82
|
-
else:
|
|
83
|
-
text_item = str(item)
|
|
84
|
-
|
|
85
|
-
# Smart word evaluation check.
|
|
86
|
-
# If a string has letters or digits (even with spaces/exclamations), it's a word track item.
|
|
87
|
-
# If it is only pure punctuation characters (like "@@@"), it goes to symbols.
|
|
88
|
-
|
|
89
|
-
if any(char.isalnum() for char in text_item):
|
|
90
|
-
if convert_numeric_strings and text_item.isdigit():
|
|
91
|
-
numbers.append(int(text_item))
|
|
92
|
-
else:
|
|
93
|
-
words.append(text_item)
|
|
94
|
-
|
|
95
|
-
else:
|
|
96
|
-
symbols.append(text_item)
|
|
97
|
-
|
|
98
|
-
# Start the engine using the dynamic argument variable
|
|
99
|
-
unpack(any_list)
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
# Sort each individual track cleanly
|
|
103
|
-
numbers.sort()
|
|
104
|
-
words.sort()
|
|
105
|
-
symbols.sort()
|
|
106
|
-
|
|
107
|
-
return {
|
|
108
|
-
"numbers": numbers,
|
|
109
|
-
"symbols": symbols,
|
|
110
|
-
"words": words,
|
|
111
|
-
"dictionaries": dict_tracks
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import collections
|
|
2
|
-
import deep_sort_list
|
|
3
|
-
|
|
4
|
-
crazy_list = [44, [3, "apple", "@#%&"], {"name": "Aadhya", "sex": "Female", "personal_details": {"is_married": False, "address": {"house_no": 448, "plot_no": 403, "strret": 'abc', "locality": "janki_nagar_extension", "pincode": 452010}, "is_employed": True}, "religion": "Hindu"}, "banana", "100", "^^^", '&', '101','222','1000', 589, [445,[28,'%','828',[45,54],'*']]]
|
|
5
|
-
|
|
6
|
-
my_list = [44, '404', 88, 100, '100', '101', "Shreya@08singh","hey, buddy",'#', '^', {"subject": "english", "marks": {"internal_marks": 75, "internal_marks_2": 88}}, 'bjbj', 22545,[44, '404', 88, 100, '100', '101','#', '^', 'bjbj', 22545, 56, [44, '404', 88, 100, '100', '101','#', '^', 'bjbj', 22545,[44,"Hello David", '404', 88, 100, '100', '101','#', '^', 'bjbj', 22545]]]]
|
|
7
|
-
|
|
8
|
-
print("------Testing List--------")
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
print("=== REQUIREMENT 1: Standard Dictionary Return ===")
|
|
12
|
-
result_crazy_list = deep_sort_list.clean_and_flatten(crazy_list)
|
|
13
|
-
result_my_list = deep_sort_list.clean_and_flatten(my_list)
|
|
14
|
-
|
|
15
|
-
print("--- CRAZY LIST ---")
|
|
16
|
-
print("Words:", result_crazy_list["words"])
|
|
17
|
-
print("Numbers:", result_crazy_list["numbers"])
|
|
18
|
-
print("Symbols:", result_crazy_list["symbols"])
|
|
19
|
-
|
|
20
|
-
print("\n--- MY LIST ----")
|
|
21
|
-
print("Words:", result_my_list["words"])
|
|
22
|
-
print("Numbers:", result_my_list["numbers"])
|
|
23
|
-
print("Symbols:", result_my_list["symbols"])
|
|
24
|
-
print("Dictionaries:", result_my_list["dictionaries"])
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
print("=== REQUIREMENT 2: Convert String Numbers to Ints ===")
|
|
28
|
-
r_crazy_list = deep_sort_list.clean_and_flatten(crazy_list, convert_numeric_strings=True)
|
|
29
|
-
r_my_list = deep_sort_list.clean_and_flatten(my_list, convert_numeric_strings=True)
|
|
30
|
-
|
|
31
|
-
print("Words", r_crazy_list["words"])
|
|
32
|
-
print("Numbers", r_crazy_list["numbers"])
|
|
33
|
-
print("Symbols", r_crazy_list["symbols"])
|
|
34
|
-
print("Dictionaries", r_crazy_list["dictionaries"])
|
|
35
|
-
|
|
36
|
-
print("--- MY LIST WITH CONVERSION ON ---")
|
|
37
|
-
print("Words:", r_my_list["words"])
|
|
38
|
-
print("Numbers:", r_my_list["numbers"])
|
|
39
|
-
print("Symbols:", r_my_list["symbols"])
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
[build-system]
|
|
2
|
-
requires = ["hatchling"]
|
|
3
|
-
build-backend = "hatchling.build"
|
|
4
|
-
|
|
5
|
-
[project]
|
|
6
|
-
name = "deep_sort_list_parser"
|
|
7
|
-
version = "1.0.6"
|
|
8
|
-
description = "A recursive data parser to flatten and sort complex nested structures safely."
|
|
9
|
-
readme = "README.md"
|
|
10
|
-
requires-python = ">=3.8"
|
|
11
|
-
authors = [
|
|
12
|
-
{ name = "Developer" }
|
|
13
|
-
]
|
|
14
|
-
classifiers = [
|
|
15
|
-
"Programming Language :: Python :: 3",
|
|
16
|
-
"License :: OSI Approved :: MIT License",
|
|
17
|
-
]
|
|
18
|
-
|
|
19
|
-
[tool.hatch.build.targets.wheel]
|
|
20
|
-
only-include = ["deep_sort_list.py"]
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
# test_suite.py
|
|
2
|
-
import collections
|
|
3
|
-
import deep_sort_list
|
|
4
|
-
|
|
5
|
-
print("Running optimized automated test suite...")
|
|
6
|
-
|
|
7
|
-
# 🔹 1. Test Sentence Spaces and Punctuation (Word vs Symbol Fix)
|
|
8
|
-
mixed_text = ["banana!", "Hello World", "@@@"]
|
|
9
|
-
res1 = deep_sort_list.clean_and_flatten(mixed_text)
|
|
10
|
-
assert res1["words"] == ["Hello World", "banana!"], f"Failed Word Fix: Got {res1['words']}"
|
|
11
|
-
assert res1["symbols"] == ["@@@"], f"Failed Symbol Fix: Got {res1['symbols']}"
|
|
12
|
-
|
|
13
|
-
# 🔹 2. Test Boolean Separation (Boolean Sorting Fix)
|
|
14
|
-
bool_list = [44, True, 0, False, 1]
|
|
15
|
-
res2 = deep_sort_list.clean_and_flatten(bool_list)
|
|
16
|
-
# Booleans should be completely absent from numbers and cleanly isolated in words!
|
|
17
|
-
assert res2["numbers"] == [0, 1, 44], f"Failed Number Separation: Got {res2['numbers']}"
|
|
18
|
-
assert res2["words"] == ["False", "True"], f"Failed Boolean Extraction: Got {res2['words']}"
|
|
19
|
-
|
|
20
|
-
# 🔹 3. Test Specialized Dictionary Support (OrderedDict Fix)
|
|
21
|
-
ordered_data = collections.OrderedDict([("z", 1), ("a", 2)])
|
|
22
|
-
res3 = deep_sort_list.clean_and_flatten(ordered_data)
|
|
23
|
-
# The engine should catch it via isinstance and process it natively into dictionaries!
|
|
24
|
-
assert res3["dictionaries"] == [{"a": 2, "z": 1}], f"Failed Sub-dict Handling: Got {res3['dictionaries']}"
|
|
25
|
-
|
|
26
|
-
print("ALL ARCHITECTURAL PASSES OK!")
|
|
27
|
-
|