realpython / realpython/python-guide
"Mutable and Immutable Types" example
未关闭
还没有人认领这个 Issue。
- 主要语言
- Batchfile
- 星标
- 29.8k
- 派生
- 5.9k
- PR 合并指标
- 30 天内没有已合并 PR
描述
The best example in the Mutable and Immutable Types section of the Structuring Your Project page is:
# create a concatenated string from 0 to 19 (e.g. "012..1819")
nums = [str(n) for n in range(20)]
print "".join(nums)
It is considered the best example for being both more efficient and succinct.
Would this be a better example to use?
''.join(map(str, range(20)))
It's more succinct and is faster:
$ python -m timeit "nums = [str(n) for n in range(20)]; ''.join(nums)"
100000 loops, best of 3: 6.84 usec per loop
$ python -m timeit "''.join(map(str, range(20)))"
100000 loops, best of 3: 4.93 usec per loop
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从链接的“Structuring Your Project”页面中的“Mutable and Immutable Types”部分开始,并将现有示例与提议的表达式进行比较。当文档使用约定的示例,并准确呈现任何性能方面的说法时,即视为完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- documentation
- Issue 类型
- 文档
- 难度
- 1/5
- 预计耗时
- 1 小时以内
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 48/100