Skip to main content

Linq for python

Project description

Linq for Python

像C#或JavaScript一样链式写python

1 代码说明

代码Fork https://pypi.org/project/py-linq/

2 新增功能

  • 新增:filter,map,find等类似于JavaScriptfilter,map,find
  • 使用函数式入口来初始化列表linq4py.array()

3 举例

import linq4py as lp

origin_items = [
    {'id': '1', 'parent_id': '', 'name': 'indicator 1', 'weight': 1, 'has_child': True},
    {'id': '2', 'parent_id': '1', 'name': 'indicator 2', 'weight': 0.6, 'has_child': True},
    {'id': '3', 'parent_id': '1', 'name': 'indicator 3', 'weight': 0.4, 'has_child': True},
    {'id': '4', 'parent_id': '2', 'name': 'indicator 4', 'weight': 0.5, 'has_child': False},
    {'id': '5', 'parent_id': '2', 'name': 'indicator 5', 'weight': 0.8, 'has_child': False},
    {'id': '6', 'parent_id': '3', 'name': 'indicator 6', 'weight': 0.8, 'has_child': False},
    {'id': '7', 'parent_id': '3', 'name': 'indicator 7', 'weight': 0.8, 'has_child': False},
]


# count demo
count = lp.array(origin_items).count(lambda item: item['has_child'])
print(count)

# filter,order_by_descending map demo
items = lp.array(origin_items).filter(lambda item: item["has_child"]).order_by_descending(
    lambda item: item['weight']).map(lambda item: (item['id'], item['name']))
print(items)

# find demo
result = lp.array(origin_items).find(lambda item: item['weight'] > 0.3)
print(result)

4 修改日志

  • 2023-04-08 重新打包
  • 2023-04-08 Fork项目并新增相关功能

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

linq4py-1.0.3.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

linq4py-1.0.3-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file linq4py-1.0.3.tar.gz.

File metadata

  • Download URL: linq4py-1.0.3.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.10.6 Windows/10

File hashes

Hashes for linq4py-1.0.3.tar.gz
Algorithm Hash digest
SHA256 479422d9d41628f18e840e2718ec29bfcd926e82e2b3d4f325a90460954e852b
MD5 cb2cda18727c3873875275756ca38deb
BLAKE2b-256 845d4987a1b9c12f3eb194b026b3cd198bccb0d3e20939d66c030792928d5598

See more details on using hashes here.

File details

Details for the file linq4py-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: linq4py-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.10.6 Windows/10

File hashes

Hashes for linq4py-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 84b88aa00a236bd147efcd9a134d88ab01a7065cbc26d4fcd3cd1d5e675d62c4
MD5 8bc3a0c39e031f042f0d39526011108b
BLAKE2b-256 8673948cd5f16ea8247655454008017f98b50c5df5c64ef3e8a49eb538141289

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page