Name | linq4py JSON |
Version |
1.0.3
JSON |
| download |
home_page | |
Summary | Linq for python |
upload_time | 2023-04-10 01:03:29 |
maintainer | |
docs_url | None |
author | six006 |
requires_python | >=3.10 |
license | |
keywords |
linq
linq for python
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# Linq for Python
像C#或JavaScript一样链式写python
## 1 代码说明
代码Fork `https://pypi.org/project/py-linq/`
## 2 新增功能
- 新增:`filter`,`map`,`find`等类似于JavaScript`filter`,`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项目并新增相关功能
Raw data
{
"_id": null,
"home_page": "",
"name": "linq4py",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": "",
"keywords": "LINQ,linq for python",
"author": "six006",
"author_email": "six006@126.com",
"download_url": "https://files.pythonhosted.org/packages/84/5d/4987a1b9c12f3eb194b026b3cd198bccb0d3e20939d66c030792928d5598/linq4py-1.0.3.tar.gz",
"platform": null,
"description": "# Linq for Python\n\n\u50cfC#\u6216JavaScript\u4e00\u6837\u94fe\u5f0f\u5199python\n\n## 1 \u4ee3\u7801\u8bf4\u660e\n\u4ee3\u7801Fork `https://pypi.org/project/py-linq/`\n\n## 2 \u65b0\u589e\u529f\u80fd\n- \u65b0\u589e\uff1a`filter`,`map`,`find`\u7b49\u7c7b\u4f3c\u4e8eJavaScript`filter`,`map`,`find`\n- \u4f7f\u7528\u51fd\u6570\u5f0f\u5165\u53e3\u6765\u521d\u59cb\u5316\u5217\u8868`linq4py.array()`\n\n## 3 \u4e3e\u4f8b\n\n```\nimport linq4py as lp\n\norigin_items = [\n {'id': '1', 'parent_id': '', 'name': 'indicator 1', 'weight': 1, 'has_child': True},\n {'id': '2', 'parent_id': '1', 'name': 'indicator 2', 'weight': 0.6, 'has_child': True},\n {'id': '3', 'parent_id': '1', 'name': 'indicator 3', 'weight': 0.4, 'has_child': True},\n {'id': '4', 'parent_id': '2', 'name': 'indicator 4', 'weight': 0.5, 'has_child': False},\n {'id': '5', 'parent_id': '2', 'name': 'indicator 5', 'weight': 0.8, 'has_child': False},\n {'id': '6', 'parent_id': '3', 'name': 'indicator 6', 'weight': 0.8, 'has_child': False},\n {'id': '7', 'parent_id': '3', 'name': 'indicator 7', 'weight': 0.8, 'has_child': False},\n]\n\n\n# count demo\ncount = lp.array(origin_items).count(lambda item: item['has_child'])\nprint(count)\n\n# filter,order_by_descending map demo\nitems = lp.array(origin_items).filter(lambda item: item[\"has_child\"]).order_by_descending(\n lambda item: item['weight']).map(lambda item: (item['id'], item['name']))\nprint(items)\n\n# find demo\nresult = lp.array(origin_items).find(lambda item: item['weight'] > 0.3)\nprint(result)\n\n```\n\n## 4 \u4fee\u6539\u65e5\u5fd7\n\n- 2023-04-08 \u91cd\u65b0\u6253\u5305\n- 2023-04-08 Fork\u9879\u76ee\u5e76\u65b0\u589e\u76f8\u5173\u529f\u80fd",
"bugtrack_url": null,
"license": "",
"summary": "Linq for python",
"version": "1.0.3",
"split_keywords": [
"linq",
"linq for python"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "8673948cd5f16ea8247655454008017f98b50c5df5c64ef3e8a49eb538141289",
"md5": "8bc3a0c39e031f042f0d39526011108b",
"sha256": "84b88aa00a236bd147efcd9a134d88ab01a7065cbc26d4fcd3cd1d5e675d62c4"
},
"downloads": -1,
"filename": "linq4py-1.0.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "8bc3a0c39e031f042f0d39526011108b",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 10154,
"upload_time": "2023-04-10T01:03:27",
"upload_time_iso_8601": "2023-04-10T01:03:27.196707Z",
"url": "https://files.pythonhosted.org/packages/86/73/948cd5f16ea8247655454008017f98b50c5df5c64ef3e8a49eb538141289/linq4py-1.0.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "845d4987a1b9c12f3eb194b026b3cd198bccb0d3e20939d66c030792928d5598",
"md5": "cb2cda18727c3873875275756ca38deb",
"sha256": "479422d9d41628f18e840e2718ec29bfcd926e82e2b3d4f325a90460954e852b"
},
"downloads": -1,
"filename": "linq4py-1.0.3.tar.gz",
"has_sig": false,
"md5_digest": "cb2cda18727c3873875275756ca38deb",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 9809,
"upload_time": "2023-04-10T01:03:29",
"upload_time_iso_8601": "2023-04-10T01:03:29.424812Z",
"url": "https://files.pythonhosted.org/packages/84/5d/4987a1b9c12f3eb194b026b3cd198bccb0d3e20939d66c030792928d5598/linq4py-1.0.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-04-10 01:03:29",
"github": false,
"gitlab": false,
"bitbucket": false,
"lcname": "linq4py"
}