Write python using js syntax
Project description
jssyntax
Write python using js syntax
Installation
pip install jssyntax
Usage
from jssyntax import List
numbers = List([1, 2, 3, 4, 5])
#forEach
list = []
numbers.forEach(lambda item, index, array:
#使用元祖来确保两个handle都在lambda表达式中
(print(f"Item: {item}, Index: {index}, Array: {array}"),
list.append(item))
)
print(list)
# 调用 map 方法
squared_numbers = numbers.map(lambda item, index, array: item ** 2)
print(squared_numbers)
even_index = numbers.findIndex(lambda item, index, array: item % 2 == 0)
print(f"第一个偶数的位置是: {even_index}")
# 使用 splice 方法
removed_elements = numbers.splice(1, 2, 10, 20)
print(f"删除的元素: {removed_elements}")
print(f"修改后的列表: {numbers}")
# 调用 filter 方法
filtered_numbers = numbers.filter(lambda item, index, array: item % 2 == 0)
print(f"过滤后的列表: {filtered_numbers}")
#push和pop
numbers.push(100)
print(numbers)
numbers.pop()
print(numbers)
# 调用 reduce 方法
sum_of_numbers = numbers.reduce(lambda acc, item, index, array: acc + item, 0)
print(f"所有数字的和是: {sum_of_numbers}")
#flatmap
print(numbers.join(","))
print(numbers.flatMap(lambda item: [item, item * 2]))
#includes
print(numbers.includes(100))
print(numbers.includes(1000))
PS:
build package:
python setup.py sdist bdist_wheel
publish:
twine upload dist/*
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
jssyntax-0.2.0.tar.gz
(4.1 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jssyntax-0.2.0.tar.gz.
File metadata
- Download URL: jssyntax-0.2.0.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f799fd2a13596f61b387589c59ee64d47f7eca4915da5f0ad77550e270d7de3a
|
|
| MD5 |
d2e58922a4a89d836efc23e3bc7a9d96
|
|
| BLAKE2b-256 |
5e9463a86920bcbc7a6df1a510562fbef1b7abd7736d608f441b6472fcdf0606
|
File details
Details for the file jssyntax-0.2.0-py3-none-any.whl.
File metadata
- Download URL: jssyntax-0.2.0-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6b2f6ba86cde7584b7d086f6b1b7354113e47ec99fc09e6c61da6d724a25df43
|
|
| MD5 |
920c339d88541634d468d8bc091e4777
|
|
| BLAKE2b-256 |
929998932495e8336a91cb253dc8f240fd3e91cc78641fc307f1288383baecad
|