Skip to content

Walrus operator is not allowed inside the iterable of a comprehension which is itself the iterable of an outer comprehension #140649

@Adarsh-Roy

Description

@Adarsh-Roy

Bug report

Bug description:

The following works:

return sum(map(prod,pairwise(c for r in b if (c:=r.count('1')))))

But the following does not work:

return sum(a*b for a,b in pairwise(c for r in b if (c:=r.count('1'))))

The error:

SyntaxError: assignment expression cannot be used in a comprehension iterable expression
                                                        ^^^^^^^^^^^^^^^
    return sum(a*b for a,b in pairwise(c for r in b if (c:=r.count('1'))))
Line 3  (Solution.py)

CPython versions tested on:

3.11

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixes3.14bugs and security fixes3.15new features, bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)pendingThe issue will be closed if no feedback is providedtopic-parser

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions