Skip to content

Releases: linjing-lab/sorting-algorithms

sortingx-1.3.2

26 Jun 09:26
Compare
Choose a tag to compare

download:

!pip install sortingx==1.3.2 # in jupyter
pip install sortingx==1.3.2 # in cmd

load package:

import sortingx as six # reduce times of __len__ returned length of __iterable than previous versions

most use:

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)
output = six.bubble(data, key=lambda x: x[1], reverse=True)
print(output == result, data == result) # True, True

more cases (recommend tuple):

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:

zero = {'Alex': 100, 'Jack': 97,  'Peter': 88, 'Li': 98}
one = six.bubble(zero) # dict
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:

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','3','2'])) # zip

sortingx-1.3.1

29 May 12:33
Compare
Choose a tag to compare

download:

!pip install sortingx==1.3.1 # in jupyter
pip install sortingx==1.3.1 # in cmd

load package:

import sortingx as six

most use:

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 (recommend tuple):

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:

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:

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','3','1'])) # zip

sortingx-1.3.0

26 Mar 09:30
Compare
Choose a tag to compare

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

sortingx-1.2.3

23 Mar 09:23
Compare
Choose a tag to compare

download:

!pip install sortingx==1.2.3 # in jupyter
pip install sortingx==1.2.3 # in cmd

fix bug: (making no use of reverse has no impact on the sorting of such issue)

import sortingx as six 
data = [['Jack', (98, 100)], ['Bob', (98, 99)], ['Jessi', (98, 97)]]
result = sorted(data, key=lambda x: x[1][0], reverse=True) 
output = six.bubble(data, key=lambda x: x[1][0], reverse=True) 

'''
True
'''

most use:

import sortingx as six
data = [('Alex', 100, 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[0], x[1]), reverse=True) # data will be deepcopyed in sorted.
output = six.bubble(data, key=lambda x: (x[0], 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', 100, 90, 98, 95), ('Jack', 97, 88, 98, 92), ('Peter', 92, 95, 92, 96), ('Li', 97, 89, 98, 92)) # tuple
# data = {('Alex', 100, 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[0], x[1]), reverse=True)
result = sorted(data, key=lambda x: (x[0], 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(6)) # range
zip_ = six.quick(zip([1, 2], [3, 4])) # zip

sortingx-1.2.2

16 Feb 09:51
Compare
Choose a tag to compare

download:

!pip install sortingx==1.2.2 # in jupyter
pip install sortingx==1.2.2 # in cmd

most use:

import sortingx as six
data = [('Alex', 100, 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[0], x[1]), reverse=True) # data will be deepcopyed in sorted.
output = six.bubble(data, key=lambda x: (x[0], 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', 100, 90, 98, 95), ('Jack', 97, 88, 98, 92), ('Peter', 92, 95, 92, 96), ('Li', 97, 89, 98, 92)) # tuple
# data = {('Alex', 100, 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[0], x[1]), reverse=True)
result = sorted(data, key=lambda x: (x[0], 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(6)) # range
zip_ = six.quick(zip([1, 2], [3, 4])) # zip

Users can click https://docs.python.org/3/howto/sorting.html for more cases about sorted() and list.sort(), and test with sortingx's methods.

sortingx-1.2.1

27 Dec 02:42
Compare
Choose a tag to compare

download:

!pip install sortingx==1.2.1 # in jupyter
pip install sortingx==1.2.1 # in cmd

examples:

import sortingx as six
data = [('Alex', 100, 90, 98, 95), ('Jack', 97, 88, 98, 92), ('Peter', 92, 95, 92, 96), ('Li', 97, 89, 98, 92)]
result = sorted(data, key=lambda x: (x[0], x[1]), reverse=True) # data will be deepcopyed in sorted.
output = six.bubble(data, key=lambda x: (x[0], x[1]), reverse=True)
print(output == result, data == result) # `output` is the return value of `data`.

'''
True, True
'''

more:

import sortingx as six
data = {('Alex', 100, 90, 98, 95), ('Jack', 97, 88, 98, 92), ('Peter', 92, 95, 92, 96), ('Li', 97, 89, 98, 92)} # set
# data = (('Alex', 100, 90, 98, 95), ('Jack', 97, 88, 98, 92), ('Peter', 92, 95, 92, 96), ('Li', 97, 89, 98, 92)) # tuple
output = six.bubble(data, key=lambda x: (x[0], x[1]), reverse=True) # when data is not `list` type, it will be converted to list. data remains its type.
result = sorted(data, key=lambda x: (x[0], x[1]), reverse=True)
print(output == result)

'''
True
'''

some cases for str, dict:

str_ = six.merge("barzilar_borwein") # str
dict_ = six.quick({'Alex': 100, 'Jack': 97,  'Peter': 88, 'Li': 98}) # dict (sort by key)

explain:

  • v1.2.1 is mainly the equivalent of v1.2.0, but the kernel of generate is more portable than v1.2.0.
  • delete core function to make comparision with built-in rules first.

sortingx-1.2.0

25 Dec 11:49
Compare
Choose a tag to compare

download:

!pip install sortingx==1.2.0 # in jupyter
pip install sortingx==1.2.0 # in cmd

examples:

import sortingx as six
data = [('Alex', 100, 90, 98, 95), ('Jack', 97, 88, 98, 92), ('Peter', 92, 95, 92, 96), ('Li', 97, 89, 98, 92)]
result = sorted(data, key=lambda x: (x[0], x[1]), reverse=True) # data will be deepcopyed in sorted.
output = six.bubble(data, key=lambda x: (x[0], x[1]), reverse=True)
print(output == result, data == result) # `output` is the return value of `data`.

'''
True, True
'''

more:

import sortingx as six
data = {('Alex', 100, 90, 98, 95), ('Jack', 97, 88, 98, 92), ('Peter', 92, 95, 92, 96), ('Li', 97, 89, 98, 92)} # set
# data = (('Alex', 100, 90, 98, 95), ('Jack', 97, 88, 98, 92), ('Peter', 92, 95, 92, 96), ('Li', 97, 89, 98, 92)) # tuple
output = six.bubble(data, key=lambda x: (x[0], x[1]), reverse=True) # # when data is not `list` type, it will be converted to list. data remains its type.
result = sorted(data, key=lambda x: (x[0], x[1]), reverse=True)
print(output == result)

'''
True
'''

some cases for str, dict:

str_ = six.merge("barzilar_borwein") # str
dict_ = six.quick({'Alex': 100, 'Jack': 97,  'Peter': 88, 'Li': 98}) # dict (sort by key)

explain:

  • the kernel of generate can better cooperate with core function than previous 4 versions.
  • comparison of str has been optimized compared with v1.1.2 and v1.1.3.

sortingx-1.1.3

29 Nov 06:26
Compare
Choose a tag to compare

download:

!pip install sortingx==1.1.3 # in jupyter
pip install sortingx==1.1.3 # in cmd

examples:

import sortingx as six
data = [('Alex', 100, 90, 98, 95), ('Jack', 97, 88, 98, 92), ('Peter', 92, 95, 92, 96), ('Li', 97, 89, 98, 92)]
# data = {('Alex', 100, 90, 98, 95), ('Jack', 97, 88, 98, 92), ('Peter', 92, 95, 92, 96), ('Li', 97, 89, 98, 92)} # set
# data = (('Alex', 100, 90, 98, 95), ('Jack', 97, 88, 98, 92), ('Peter', 92, 95, 92, 96), ('Li', 97, 89, 98, 92)) # tuple
output = six.bubble(data, key=lambda x: (x[0], x[1]), reverse=True)
result = sorted(data, key=lambda x: (x[0], x[1]), reverse=True)
print(output == result)

'''
True
'''

some cases for str, dict:

str_ = six.merge("barzilar_borwein", reverse=True) # str
dict_ = six.quick({'Alex': 100, 'Jack': 97,  'Peter': 88, 'Li': 98}) # dict (sort by key)

explain:

  • typing check with more local values to indicate them in functions.
  • the software usage is aligned with part of sorted() usage methods.

sortingx-1.1.2

10 Nov 18:37
Compare
Choose a tag to compare

download:

!pip install sortingx==1.1.2 # in jupyter
pip install sortingx==1.1.2 # in cmd

different:
sortingx only allowed list data and don't return a value in any of 6 methods in v1.1.1, but it can return a sorted result and support more iterable data in this version, like tuple, dict, set, str.

examples:

import sortingx as six
data = [('Alex', 100, 90, 98, 95), ('Jack', 97, 88, 98, 92), ('Peter', 92, 95, 92, 96), ('Li', 97, 89, 98, 92)]
# data = {('Alex', 100, 90, 98, 95), ('Jack', 97, 88, 98, 92), ('Peter', 92, 95, 92, 96), ('Li', 97, 89, 98, 92)} # set
# data = (('Alex', 100, 90, 98, 95), ('Jack', 97, 88, 98, 92), ('Peter', 92, 95, 92, 96), ('Li', 97, 89, 98, 92)) # tuple
output = six.bubble(data, key=lambda x: (x[0], x[1]), reverse=True)
result = sorted(data, key=lambda x: (x[0], x[1]), reverse=True)
print(output == result)

'''
True
'''

some cases for str, dict:

str_ = six.merge("barzilar_borwein", reverse=True) # str
dict_ = six.quick({'Alex': 100, 'Jack': 97,  'Peter': 88, 'Li': 98}) # dict (sort by key)

explain:

  • use convert to support dict, tuple, set, str, better robustness than v1.1.1.
  • with a return value to make sure print(method) can be used in experiment.

sortingx-1.1.1

10 Nov 13:45
Compare
Choose a tag to compare

download:

!pip install sortingx==1.1.1 # in jupyter
pip install sortingx==1.1.1 # in cmd

example:

import sortingx as six
data = [('Alex', 100, 90, 98, 95), ('Jack', 97, 88, 98, 92), ('Peter', 92, 95, 92, 96), ('Li', 97, 89, 98, 92)]
six.bubble(data, key=lambda x: (x[0], x[1]), reverse=True) # v1.1.1 only allows `list` data with in-place sorting, but typing is better.
# sorted(data, key=lambda x: (x[0], x[1]), reverse=False)
print(data)

'''
[('Peter', 92, 95, 92, 96), ('Jack', 97, 88, 98, 92), ('Li', 97, 89, 98, 92), ('Alex', 100, 90, 98, 95)]
'''

explain:

  • use typing_extensions to accelerate typing check.
  • better data exchanging and editor search presentation.

sortingx (mainly the extension of list.sort()):

sorted():