• Traceback error "Sort array by element frequency"


I would like to give some feedback about my strange error when trying to check my code.


import numpy as np

def frequency_sort(items):
    if items == []: return []
    if items == [1]: return [1]
    a = np.array([items[0],items.count(items[0])])
    for i in range(len(items)-1):
        b = np.array([items[i+1],items.count(items[i+1])])
        a = np.vstack((a,b))
    a = np.flipud(a)
    c = a[a[:,1].argsort(kind='mergesort')[::-1]]
    d = c[:,0]
    return d


Traceback (most recent call last):, File "/home/site/checkio/runners/py32.py", line 252, in echosendrecvjson, datasend = json.dumps(send), File "/usr/local/lib/python3.8/json/init.py", line 231, in dumps, return defaultencoder.encode(obj), File "/usr/local/lib/python3.8/json/encoder.py", line 199, in encode, chunks = self.iterencode(o, oneshot=True), File "/usr/local/lib/python3.8/json/encoder.py", line 257, in iterencode, return iterencode(o, 0), File "/usr/local/lib/python3.8/json/encoder.py", line 179, in default, raise TypeError(f'Object of type {o.class.name} ',TypeError: Object of type int64 is not JSON serializable,,During handling of the above exception, another exception occurred:,,Traceback (most recent call last):, File "/home/site/checkio/runners/py32.py", line 486, in <module>, rundata = echosendrecvjson(globals()'do' + rundata['do']), File "/home/site/checkio/runners/py32.py", line 255, in echosendrecvjson, error = u'TypeError: {0} is wrong data type'.format(cgi.escape(str(type(result)))),AttributeError: module 'cgi' has no attribute 'escape', Fail: frequency_sort([4,6,2,2,6,4,4,4]) PyCharm. The Python IDE for Professional Developers. Enjoy productive Python, web and scientific development with PyCharm. Download it now!

From: https://py.checkio.org/mission/sort-array-by-element-frequency/solve/


Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:69.0) Gecko/20100101 Firefox/69.0