Skip to content

Reconsider recommending map over list comprehensions #968

Closed
@gbrova

Description

@gbrova

Currently the examples in the structure section imply a list comprehension is "Better"

# create a concatenated string from 0 to 19 (e.g. "012..1819")
nums = [str(n) for n in range(20)]
print "".join(nums)

but using map is "Best"

# create a concatenated string from 0 to 19 (e.g. "012..1819")
nums = map(str, range(20))
print "".join(nums)

However, the guide doesn't recommend one approach over the other in the style section.

My impression is most people prefer list comprehensions because they are cleaner even if sometimes microscopically slower. See e.g. a discussion on StackOverflow and Google's style guide.

Is it intentional to recommend map over list comprehensions? If yes, we should add this recommendation in the style section for consistency; if not, we should remove the recommendation in the structure section. FWIW, my preference is list comprehensions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions