sortingx-1.3.0
download:
!pip install sortingx==1.3.0 # in jupyter
pip install sortingx==1.3.0 # in cmd
optimize about:
if compare[l] != compare[r]: # l, r are according to certain algorithm
__iterable[l], __iterable[r] = __iterable[r], __iterable[r]
if key != None:
compare[l], compare[r] = compare[r], compare[l]
change <
to <=
and >
to >=
in insert
and merge
to optimize time complexity.
most use:
import sortingx as six
data = [('Alex', 97, 90, 98, 95), ('Jack', 97, 88, 98, 92), ('Peter', 92, 95, 92, 96), ('Li', 97, 89, 98, 92)] # list
result = sorted(data, key=lambda x: x[1], reverse=True) # data will be deepcopyed in sorted.
output = six.bubble(data, key=lambda x: x[1], reverse=True)
print(output == result, data == result) # `output` is the return value of `data`.
'''
True, True
'''
more cases (when data is not list
type, it will be converted to list
. data remains its type.):
import sortingx as six
data = (('Alex', 97, 90, 98, 95), ('Jack', 97, 88, 98, 92), ('Peter', 92, 95, 92, 96), ('Li', 97, 89, 98, 92)) # tuple
# data = {('Alex', 97, 90, 98, 95), ('Jack', 97, 88, 98, 92), ('Peter', 92, 95, 92, 96), ('Li', 97, 89, 98, 92)} # set
output = six.bubble(data, key=lambda x: x[1], reverse=True)
result = sorted(data, key=lambda x: x[1], reverse=True)
print(output == result)
'''
True
'''
The current version support the dict, dict_keys, dict_values, dict_items:
import sortingx as six
zero = {'Alex': 100, 'Jack': 97, 'Peter': 88, 'Li': 98}
one = six.bubble(zero) # dict (sort by key, and return a list)
two = six.insert(zero.keys(), key=str.lower) # dict_keys
three = six.shell(zero.values()) # dict_values
four = six.heap(zero.items(), key=lambda x: x[0]) # sort by key
five = six.quick(zero.items(), key=lambda x: x[1]) # sort by value
some cases for str, range, zip:
import sortingx as six
str_ = six.bubble("barzilar_borwein") # str
range_l = six.merge(range(1 << 20), reverse=True) # long range
range_ = six.shell(range(9)) # range
zip_ = six.quick(zip(['1.1.0', '1.1.1', '1.1.2', '1.1.3'], ['1.2.0', '1.2.1', '1.2.2', '1.2.3'])) # zip