https://github.com/lucifer1004/jl2py.jl
Transpile from Julia to Python
https://github.com/lucifer1004/jl2py.jl
julia python transpiler
Last synced: 4 months ago
JSON representation
Transpile from Julia to Python
- Host: GitHub
- URL: https://github.com/lucifer1004/jl2py.jl
- Owner: lucifer1004
- License: mit
- Created: 2022-03-16T14:32:00.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-11-14T17:32:20.000Z (over 1 year ago)
- Last Synced: 2025-03-24T12:56:19.833Z (about 1 year ago)
- Topics: julia, python, transpiler
- Language: Julia
- Homepage:
- Size: 202 KB
- Stars: 17
- Watchers: 2
- Forks: 0
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Citation: CITATION.bib
Awesome Lists containing this project
README
# Jl2Py
[](https://lucifer1004.github.io/Jl2Py.jl/stable)
[](https://lucifer1004.github.io/Jl2Py.jl/dev)
[](https://github.com/lucifer1004/Jl2Py.jl/actions/workflows/CI.yml?query=branch%3Amain)
[](https://codecov.io/gh/lucifer1004/Jl2Py.jl)
## Examples
Conversion results of [LeetCode.jl - 1. Two Sum](https://github.com/JuliaCN/LeetCode.jl/blob/master/src/problems/1.two-sum.jl)
```python
def two_sum(nums: List[int], target: int, /) -> Union[None, Tuple[int, int]]:
seen = {}
for (i, n) in enumerate(nums):
m = target - n
if haskey(seen, m):
return (seen[m], i)
else:
seen[n] = i
```
Conversion results of [LeetCode.jl - 2. Add Two Numbers](https://github.com/JuliaCN/LeetCode.jl/blob/master/src/problems/2.add-two-numbers.jl)
```python
def add_two_numbers(l1: ListNode, l2: ListNode, /) -> ListNode:
carry = 0
fake_head = cur = ListNode()
while not isnothing(l1) or (not isnothing(l2) or not iszero(carry)):
(v1, v2) = (0, 0)
if not isnothing(l1):
v1 = val(l1)
l1 = next(l1)
if not isnothing(l2):
v2 = val(l2)
l2 = next(l2)
(carry, v) = divrem(v1 + v2 + carry, 10)
next_inplace(cur, ListNode(v))
cur = next(cur)
val_inplace(cur, v)
return next(fake_head)
```
We can see that we only need to define a few polyfill functions to make the generated Python code work.