sortbydict 0.1.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.
- sortbydict-0.1.0/.gitignore +5 -0
- sortbydict-0.1.0/LICENSE +7 -0
- sortbydict-0.1.0/PKG-INFO +19 -0
- sortbydict-0.1.0/README.md +0 -0
- sortbydict-0.1.0/pyproject.toml +39 -0
- sortbydict-0.1.0/src/sortbydict/__init__.py +10 -0
- sortbydict-0.1.0/src/sortbydict/core.py +35 -0
- sortbydict-0.1.0/src/sortbydict/utils.py +1 -0
sortbydict-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2026 Tang Zhilin (https://github.com/lucas-linlin)
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sortbydict
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A Python sort algorithm to sort any types of objects.
|
|
5
|
+
Project-URL: Homepage, https://github.com/Lucas-Linlin/sortbydict
|
|
6
|
+
Project-URL: Issues, https://github.com/Lucas-Linlin/sortbydict/issues
|
|
7
|
+
Author-email: Tang Zhilin <Lin_LUCAS@hotmail.com>
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
19
|
+
Requires-Python: >=3.14
|
|
File without changes
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling >= 1.26"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "sortbydict"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
authors = [
|
|
9
|
+
{ name="Tang Zhilin", email="Lin_LUCAS@hotmail.com" },
|
|
10
|
+
]
|
|
11
|
+
description = "A Python sort algorithm to sort any types of objects."
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
requires-python = ">=3.14"
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 3 - Alpha",
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"Programming Language :: Python :: 3.10",
|
|
18
|
+
"Programming Language :: Python :: 3.11",
|
|
19
|
+
"Programming Language :: Python :: 3.12",
|
|
20
|
+
"Programming Language :: Python :: 3.13",
|
|
21
|
+
"Programming Language :: Python :: 3.14",
|
|
22
|
+
"Intended Audience :: Developers",
|
|
23
|
+
"Operating System :: OS Independent",
|
|
24
|
+
]
|
|
25
|
+
license = "MIT"
|
|
26
|
+
license-files = ["LICEN[CS]E*"]
|
|
27
|
+
|
|
28
|
+
[project.urls]
|
|
29
|
+
Homepage = "https://github.com/Lucas-Linlin/sortbydict"
|
|
30
|
+
Issues = "https://github.com/Lucas-Linlin/sortbydict/issues"
|
|
31
|
+
|
|
32
|
+
[tool.pytest.ini_options]
|
|
33
|
+
testpaths = ["tests"]
|
|
34
|
+
doctest_modules = true
|
|
35
|
+
addopts = [
|
|
36
|
+
"--doctest-modules",
|
|
37
|
+
"-v",
|
|
38
|
+
"--strict-markers",
|
|
39
|
+
]
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'''
|
|
2
|
+
sortbydict: a dict-based linear time sort tool.
|
|
3
|
+
The software has the capacity to provide a rapid sorting method and to support the sorting of lists containing any number of objects of the same type concurrently.
|
|
4
|
+
'''
|
|
5
|
+
|
|
6
|
+
__version__ = '0.1.0'
|
|
7
|
+
from sortbydict.core import *
|
|
8
|
+
from sortbydict.utils import *
|
|
9
|
+
|
|
10
|
+
# __all__ =
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from sortbydict.utils import *
|
|
2
|
+
from typing import TypeVar,Callable
|
|
3
|
+
T = TypeVar('T')
|
|
4
|
+
BUILTIN_TYPES = (int,float,str,bytes)
|
|
5
|
+
def sort_by_dict(data: list[T], func: None | Callable = None, /) -> list[T]:
|
|
6
|
+
"""A function to sort a list of objects of any type.
|
|
7
|
+
Args:
|
|
8
|
+
data (list): List of objects to be sorted.
|
|
9
|
+
func (callable): A function to map each item in the list to an integer to use as the sort key.
|
|
10
|
+
|
|
11
|
+
Returns:
|
|
12
|
+
out (list): The new sorted list.
|
|
13
|
+
|
|
14
|
+
Note: **The sorted list is not the same object as the original list `data`.**
|
|
15
|
+
|
|
16
|
+
Raises:
|
|
17
|
+
TypeError: If the object types in the list are not consistent.
|
|
18
|
+
TypeError: If the type of object is not supported by the `func` function.
|
|
19
|
+
SortError: If the `func` function raises an error except `TypeError`.
|
|
20
|
+
|
|
21
|
+
Examples:
|
|
22
|
+
>>> l1 = [6,8,2,5,3]
|
|
23
|
+
>>> l2 = sort_by_dict(l1)
|
|
24
|
+
>>> l2
|
|
25
|
+
[2, 3, 5, 6, 8]
|
|
26
|
+
>>> l2 is l1
|
|
27
|
+
False"""
|
|
28
|
+
tp = type(data[0])
|
|
29
|
+
if func is None:
|
|
30
|
+
if tp not in BUILTIN_TYPES:
|
|
31
|
+
raise TypeError(f'the type {tp} is not supported because no functions are provided.')
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
srtd = []
|
|
35
|
+
return srtd
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
class SortError(Exception):pass
|