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

fix map() statement in list comprehension example #60277

Closed
cjerdonek opened this issue Sep 28, 2012 · 5 comments
Closed

fix map() statement in list comprehension example #60277

cjerdonek opened this issue Sep 28, 2012 · 5 comments
Assignees
Labels
docs Documentation in the Doc dir easy type-feature A feature request or enhancement

Comments

@cjerdonek
Copy link
Member

BPO 16073
Nosy @cjerdonek
Files
  • issue16073.patch
  • 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/cjerdonek'
    closed_at = <Date 2012-09-28.14:30:14.454>
    created_at = <Date 2012-09-28.03:50:23.772>
    labels = ['easy', 'type-feature', 'docs']
    title = 'fix map() statement in list comprehension example'
    updated_at = <Date 2012-09-28.14:30:14.453>
    user = 'https://github.com/cjerdonek'

    bugs.python.org fields:

    activity = <Date 2012-09-28.14:30:14.453>
    actor = 'chris.jerdonek'
    assignee = 'chris.jerdonek'
    closed = True
    closed_date = <Date 2012-09-28.14:30:14.454>
    closer = 'chris.jerdonek'
    components = ['Documentation']
    creation = <Date 2012-09-28.03:50:23.772>
    creator = 'chris.jerdonek'
    dependencies = []
    files = ['27332']
    hgrepos = []
    issue_num = 16073
    keywords = ['patch', 'easy']
    message_count = 5.0
    messages = ['171405', '171459', '171468', '171474', '171476']
    nosy_count = 4.0
    nosy_names = ['chris.jerdonek', 'docs@python', 'python-dev', 'inglesp']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue16073'
    versions = ['Python 3.2', 'Python 3.3']

    @cjerdonek
    Copy link
    Member Author

    Date: Thu, 20 Sep 2012 15:14:36 -0400
    To: docs@python.org
    Subject: [docs] map objects are not lists

    5.1.3. List Comprehensions<http://docs.python.org/dev/tutorial/datastructures.html#list-comprehensions\>

    List comprehensions provide a concise way to create lists. Common
    applications are to make new lists where each element is the result of some
    operations applied to each member of another sequence or iterable, or to
    create a subsequence of those elements that satisfy a certain condition.

    For example, assume we want to create a list of squares, like:
    >>>

    >>> squares = []>>> for x in range(10):... squares.append(x**2)...>>> squares[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]

    We can obtain the same result with:

    squares = [x**2 for x in range(10)]

    This is also equivalent to squares = map(lambda x: x**2, range(10)), but
    it?s more concise and readable.

    I think that the last sentence above should read:

    squares = list(map(lambda x: x**2, range(10)))

    In other words, the map function returns a map object, not a list object,
    so the list() function needs to be used to convert it to something that is
    truly equivalent to the previous definitions of "squares". (In case it
    matters, I am using Python-3.3.0rc2 on RHEL 6.3.)

    (from http://mail.python.org/pipermail/docs/2012-September/010525.html )

    @cjerdonek cjerdonek added docs Documentation in the Doc dir easy type-feature A feature request or enhancement labels Sep 28, 2012
    @inglesp
    Copy link
    Mannequin

    inglesp mannequin commented Sep 28, 2012

    Have attached a patch with suggested update.

    Have also grepped for similar issues elsewhere in documentation, and haven't found anything, but may have missed something.

    @cjerdonek
    Copy link
    Member Author

    2.7 is not affected.

    @cjerdonek cjerdonek assigned cjerdonek and unassigned docspython Sep 28, 2012
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Sep 28, 2012

    New changeset 6c96878eb729 by Chris Jerdonek in branch '3.2':
    Close issue bpo-16073: fix map() example in list comprehension documentation.
    http://hg.python.org/cpython/rev/6c96878eb729

    New changeset 8a4a88b1e964 by Chris Jerdonek in branch 'default':
    Close issue bpo-16073: merge fix from 3.2.
    http://hg.python.org/cpython/rev/8a4a88b1e964

    @cjerdonek
    Copy link
    Member Author

    Thanks for helping with the patch and search, Peter.

    @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
    docs Documentation in the Doc dir easy type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant