Document usage of comprehensions with multiple if clauses
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
Documentation
As noted in the documentation for list comprehensions (and also in the reference docs on expressions, but not in the glossary which refers to an "if clause" in the singular), list/set/dict comprehensions can accept zero or more if clauses like so:
[i for i in range(10) if i % 2 if i % 3]
Looking at the bytecode generated with python -m dis, this appears to be strictly equivalent to:
[i for i in range(10) if i % 2 and i % 3]
(The last if was replaced by and)
It would be nice if this was documented, and ideally with examples.
I'm also personally curious why that feature exists so if someone could point me to an explanation I'd appreciate it. I didn't find anything in what I believe is the original PEP for list comprehensions (PEP 202).
Linked PRs
- gh-138217
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先查看链接的 PR gh-138217,然后比较 issue 中提到的列表推导式教程、表达式参考和术语表部分。完成标准是文档说明 comprehensions 支持多个 if 子句,并包含一个具有代表性的示例;如果现有参考资料能够支持该理由,则添加相应的理由。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- documentation
- Issue 类型
- 文档
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 35/100