selfteaching / selfteaching/selfteaching-python-camp

Day09 elements 的原理

Open
#1,232 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
151
Forks
875
PR merge metrics
No merged PRs in 30d

Description

今天看资料的是否,发现elements()方法在资料是用sorted()进行了转换了的,不太理解sorted()的作用是啥,说是返回一个iterator类型。
我测试了一下,发现结果和用list()转换是一样的,并且不能被str和dictionary所转换,如果不做转换打印出来的结果为<itertools.chain object at 0x000002496EE09198>
后来和教练讨论之后得知,elements()函数虽然返回是一个itertools对象,但是只能被list()结构承接,自定义结构也是不行的。
现在不太理解既然只能被list转换,为什么在底层要返回一个iterator类型,为什么不干脆返回list结构呢?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No project file or test is named. Start with the referenced material on elements(), sorted(), list(), and itertools.chain, then verify the reported behavior in a minimal Python example. Done means the learning material clearly explains the observed iterator behavior and how it should be handled.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.