Skip to content

Use collections.Counter instead of a dict in terminal.py #7868

@Zac-HD

Description

@Zac-HD

Consider the following code defining counts, and the similar counts_by_filename below:

counts: Dict[str, int] = {}
for item in items:
name = item.nodeid.split("::", 1)[0]
counts[name] = counts.get(name, 0) + 1

This is a classic case for collections.Counter, and would make a great first pull request!

Example solution initialising the Counter from an iterable:

counts = Counter(... for item in items)  # you fill in the ... part

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueeasy issue that is friendly to new contributortype: refactoringinternal improvements to the code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions