0

Python,,,,,,,How can I get the number that repeats the most in four five-digit numbers starting with the first digit?

Example 12345 23455 13451 ------------------- 13455 There is any way I can do this on python?

15th Jul 2020, 12:24 AM
Pedro
4 Respostas
+ 2
If you're looking for the most common reoccurring digit from a series of multi-digit numbers, one of the simplest ways I can think of is to convert them to a string and concatenate them together. Then use the collections.Counter() class to get the most_common() element as a list of (char, count) tuple and get the char from the tuple. from collections import Counter # these lines may change depending # on how you get your numbers nums = [12345, 23455, 13451, 13455] nums = list(map(str, nums)) count = Counter(''.join(nums)) print(count.most_common(1)[0][0]) https://docs.python.org/2/library/collections.html
15th Jul 2020, 4:19 AM
ChaoticDawg
ChaoticDawg - avatar
0
Hmm you can do it with numpy and many more ways are there but don't think that any one will provide you the code you need to first try for yourself. Share your attempt with us.
15th Jul 2020, 12:32 AM
Ayush Kumar
Ayush Kumar - avatar
0
You can make an attempt first and do your searching and if something is confusing, we will be glad to help!
15th Jul 2020, 12:34 AM
Ali Abdelhady
Ali Abdelhady - avatar
0
Thank you for the explanation, I use the counter but just for one number , I will try like you said thanks
15th Jul 2020, 7:39 AM
Pedro