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
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.
0
You can make an attempt first and do your searching and if something is confusing, we will be glad to help!
0
Thank you for the explanation, I use the counter but just for one number , I will try like you said thanks