mardi 31 janvier 2023

capturing occurrences and finding its count in a list

I have a situation where a list of last occurrences is available. Say the list is. ['user', 'user', 'sys', 'sys', 'user', 'user', 'sys', 'user'] So the ask is if a user has occurred how many times did it occur consecutively? if there is a change in element say 'sys' instead of 'user' the count should start fresh. The output I am looking for is [('user', 2), ('sys', 2), ('user', 2), ('sys', 1), ('user', 1)] this would help me identify the pattern the user and system is following. Any help is much appreciated.

Aucun commentaire:

Enregistrer un commentaire