How to use an anonymous function with juliacall in python

40 Views Asked by At

I am new to julia and juliacall and i would like to use the following code in julia in python exploiting juliacall:

sort(collect(countmap(x)), by = tuple -> last(tuple), rev=true)

In my code i didn't know how to convert the anonymous function (tuple -> last(tuple)). x is the type Vector{DitStr{2, 8, Int64}}. My attempt was:

from juliacall import Main as jl

jl.sort(jl.collect(jl.countmap(x)), by= jl.last(tuple), rev=true)

but i got this error:

Traceback (most recent call last):
  File "/home/path/PycharmProjects/path/exp1.py", line 156, in <module>
    start = time()
  File "/home/path/PycharmProjects/path/exp1.py", line 84, in check_IS
    return convert_DitStr_to_python(x, b)
  File "/home/path/PycharmProjects/path/exp1.py", line 102, in convert_DitStr_to_python
    top = jl.sort(jl.collect(jl.countmap(x)), by= jl.last(tuple), rev=true)
  File "/home/path/.julia/packages/PythonCall/1f5yE/src/jlwrap/any.jl", line 208, in __call__
    return self._jl_callmethod($(pyjl_methodnum(pyjlany_call)), args, kwargs)
AttributeError: type object 'tuple' has no attribute 'n'

This is the framework, but i would like to know how to use an anonymous function with juliacall

0

There are 0 best solutions below