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 hashes)

Uploaded Source

Built Distribution

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

Uploaded Python 3

Supported by

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