Skip to content
Advertisement

How to count the same (identical) titles in a row

Good day everyone. I’m trying to count title of soccer team in list of dictionaries.

JavaScript

There are 10 (sometimes 20) games in list with data. So, home_team in list – looks like: {Team 1, … }, {Team 1, … }, {Team 2, … }, {Team 2, … }, {Team 1, … }, {Team 2, … }, {Team 2, … }, {Team 2, … }, {Team 2, … }.

I want a result of counting that looks like this: Team 1: 2; Team 2: 2; Team 1: 1, Team 2: 4.

JavaScript

And i’m stuck. Should I use a collections or pandas? And how to do that?

List:

JavaScript

Advertisement

Answer

Use itertools.groupby:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement