deep-sort-list-parser 1.0.0__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.
@@ -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
File without changes
@@ -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,27 @@
1
+ import deep_sort_list
2
+
3
+ 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],'*']]]
4
+
5
+ my_list = [44, '404', 88, 100, '100', '101','#', '^', {"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, '404', 88, 100, '100', '101','#', '^', 'bjbj', 22545]]]]
6
+
7
+ print("------Testing List--------")
8
+
9
+
10
+ print("=== REQUIREMENT 1: Standard Dictionary Return ===")
11
+ result_crazy_list = deep_sort_list.clean_and_flatten(crazy_list)
12
+ result_my_list = deep_sort_list.clean_and_flatten(my_list)
13
+
14
+ print("Words", result_crazy_list["words"])
15
+ print("Numbers", result_crazy_list["numbers"])
16
+ print("Symbols", result_crazy_list["symbols"])
17
+ print("Dictionaries", result_crazy_list["dictionaries"])
18
+
19
+
20
+ print("=== REQUIREMENT 1: Convert String Numbers to Ints ===")
21
+ r_crazy_list = deep_sort_list.clean_and_flatten(crazy_list, convert_numeric_strings=True)
22
+ r_my_list = deep_sort_list.clean_and_flatten(my_list, convert_numeric_strings=True)
23
+
24
+ print("Words", r_crazy_list["words"])
25
+ print("Numbers", r_crazy_list["numbers"])
26
+ print("Symbols", r_crazy_list["symbols"])
27
+ print("Dictionaries", r_crazy_list["dictionaries"])
@@ -0,0 +1,24 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "deep_sort_list_parser"
7
+ version = "1.0.0"
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
+
@@ -0,0 +1,35 @@
1
+ import deep_sort_list
2
+
3
+ print("Running automated test suite...")
4
+
5
+ # 🔹 Scenario 1: Standalone Single Input (The entryway protection check)
6
+ res1 = deep_sort_list.clean_and_flatten(8)
7
+ assert res1["numbers"] == [8], f"Failed Scenario 1: Expected [8], got {res1['numbers']}"
8
+
9
+ # 🔹 Scenario 2: Standard Mixed List with Empty Containers & Booleans
10
+ weird_list = [2, [], True, False, "apple"]
11
+ res2 = deep_sort_list.clean_and_flatten(weird_list)
12
+ # Remember: False is 0, True is 1 mathematically!
13
+ assert res2["numbers"] == [False, True, 2], f"Failed Scenario 2 Numbers: Got {res2['numbers']}"
14
+ assert res2["words"] == ["apple"], f"Failed Scenario 2 Words"
15
+
16
+ # 🔹 Scenario 3: String Number Conversion Toggle (True vs False)
17
+ mixed_digits = ["100", "banana", 44]
18
+
19
+ # Test with Conversion OFF (Default)
20
+ res3_off = deep_sort_list.clean_and_flatten(mixed_digits)
21
+ assert res3_off["words"] == ["100", "banana"], "Failed Scenario 3 OFF"
22
+
23
+ # Test with Conversion ON
24
+ res3_on = deep_sort_list.clean_and_flatten(mixed_digits, convert_numeric_strings=True)
25
+ assert res3_on["numbers"] == [44, 100], f"Failed Scenario 3 ON Numbers: Got {res3_on['numbers']}"
26
+ assert res3_on["words"] == ["banana"], "Failed Scenario 3 ON Words"
27
+
28
+ # 🔹 Scenario 4: Deep Multi-Nested Dictionary Locker Sorting
29
+ nested_dict = [{"sex": "Female", "name": {"last": "Singh", "first": "Shreya"}}]
30
+ res4 = deep_sort_list.clean_and_flatten(nested_dict)
31
+
32
+ expected_dict = [{'name': {'first': 'Shreya', 'last': 'Singh'}, 'sex': 'Female'}]
33
+ assert res4["dictionaries"] == expected_dict, f"Failed Scenario 4 Locker Sort"
34
+
35
+ print("ALL SCENARIOS PASSED PERFECTLY! Your library is bulletproof.")