Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tutorial, 5.6 Looping Techniques, sorted() example #83886

Closed
mirwi mannequin opened this issue Feb 21, 2020 · 6 comments
Closed

Tutorial, 5.6 Looping Techniques, sorted() example #83886

mirwi mannequin opened this issue Feb 21, 2020 · 6 comments
Assignees
Labels
3.9 only security fixes docs Documentation in the Doc dir type-feature A feature request or enhancement

Comments

@mirwi
Copy link
Mannequin

mirwi mannequin commented Feb 21, 2020

BPO 39705
Nosy @rhettinger, @ericvsmith, @rahul-kumi
PRs
  • bpo-39705 : sorted() tutorial example under looping techniques improved #18999
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/rhettinger'
    closed_at = <Date 2020-05-18.01:32:59.686>
    created_at = <Date 2020-02-21.09:24:31.422>
    labels = ['type-feature', '3.9', 'docs']
    title = 'Tutorial, 5.6 Looping Techniques, sorted() example'
    updated_at = <Date 2020-05-18.01:32:59.685>
    user = 'https://bugs.python.org/mirwi'

    bugs.python.org fields:

    activity = <Date 2020-05-18.01:32:59.685>
    actor = 'rhettinger'
    assignee = 'rhettinger'
    closed = True
    closed_date = <Date 2020-05-18.01:32:59.686>
    closer = 'rhettinger'
    components = ['Documentation']
    creation = <Date 2020-02-21.09:24:31.422>
    creator = 'mirwi'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 39705
    keywords = ['patch']
    message_count = 6.0
    messages = ['362395', '362398', '362415', '362422', '362650', '369158']
    nosy_count = 5.0
    nosy_names = ['rhettinger', 'eric.smith', 'docs@python', 'mirwi', 'rahul-kumi']
    pr_nums = ['18999']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue39705'
    versions = ['Python 3.9']

    @mirwi
    Copy link
    Mannequin Author

    mirwi mannequin commented Feb 21, 2020

    >>> basket = ['apple', 'orange', 'apple', 'pear', 'orange', 'banana']
    >>> for f in sorted(set(basket)):
    ...     print(f)
    ...
    apple
    banana
    orange
    pear

    Shouldn't 'apple' appear two times as basket is a list that allows duplicates, not a set?

    I'm just doing my first steps into Python and may be mislead. In that case, sorry for the fuzz.

    @mirwi mirwi mannequin assigned docspython Feb 21, 2020
    @mirwi mirwi mannequin added 3.9 only security fixes docs Documentation in the Doc dir type-feature A feature request or enhancement labels Feb 21, 2020
    @mirwi mirwi mannequin assigned docspython Feb 21, 2020
    @mirwi mirwi mannequin added 3.9 only security fixes docs Documentation in the Doc dir type-feature A feature request or enhancement labels Feb 21, 2020
    @ericvsmith
    Copy link
    Member

    The code is converting to a set first, then calls sorted() on that set. So "apple" is removed when the set is created.

    I'm not sure the example should throw in creating a set while it's talking about sorting.

    @rhettinger
    Copy link
    Contributor

    I prefer to keep the example as-is. It is an idiomatic way to loop over sets. The introductory text can be modified to explain that sets eliminate duplicates, that sets are ordered, and that sorted() puts them back in a deterministic order.

    @rhettinger rhettinger assigned rhettinger and unassigned docspython Feb 21, 2020
    @ericvsmith
    Copy link
    Member

    That sounds like a good improvement, Raymond.

    @rahul-kumi
    Copy link
    Mannequin

    rahul-kumi mannequin commented Feb 25, 2020

    I would like to work on this documentation improvement task.
    Please help me understand if this is not being worked on already.

    @rhettinger
    Copy link
    Contributor

    New changeset eefd4e0 by Rahul Kumaresan in branch 'master':
    bpo-39705 : sorted() tutorial example under looping techniques improved (GH-18999)
    eefd4e0

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.9 only security fixes docs Documentation in the Doc dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants