Skip to content

Confusing sentence in style.rst: "If you know the length of a list or tuple" #322

Closed
@AloisMahdal

Description

@AloisMahdal

In style.rst, AKA "Coding style", the "Unpacking" section starts with quite a confusing sentence:

If you know the length of a list or tuple, you can assign names
to its elements with unpacking:

for index, item in enumerate(some_list):
    # do something with index and item

The author is apparently referring to the tuple returned by enumerate() built-in: we know its length is 2, so we can unpack it to 2 variables.

However, especially for reader new to Python, this might be confusing. The reader might assume that the list in question is some_list, but then what does this have to do with length?

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