Home > Software engineering >  Recognize and Detect Periodic Numbers in Python
Recognize and Detect Periodic Numbers in Python

Time:11-28

im trying to detect periodic numbers in a python array.

Example: [1,5,2,1,4,1,5,2,1,4,1,5,2,1,4]

Expected Output:

[1,5,2,1,4]

The sequence is different each time, so unfortunately I don't have a pattern. I am grateful for any advice!

CodePudding user response:

You can use Collection package like that:

import collections

a = [1,5,2,1,4,1,5,2,1,4,1,5,2,1,4]

print([item for item, count in collections.Counter(a).items() if count > 1])

and output:

[1, 5, 2, 4]

CodePudding user response:

Did you consider using numpy: Similar question

  • Related