Exemplo n.º 1
0
 def test_top_1(self):
     self.assertListEqual(top_1([1 , 1, 2, 2, 3]), [1, 2])
     self.assertListEqual(top_1([1, 2, 3, 324, 234, 23, 23, 1, 23, 23]), [23])
Exemplo n.º 2
0
"""
This algorithm receives an array and returns most_frequent_value
Also, sometimes it is possible to have multiple 'most_frequent_value's,
so this function returns a list. This result can be used to find a
representative value in an array.
This algorithm gets an array, makes a dictionary of it,
 finds the most frequent count, and makes the result list.
For example: top_1([1, 1, 2, 2, 3, 4]) will return [1, 2]
(TL:DR) Get mathematical Mode
Complexity: O(n)
"""
from algorithms.arrays import top_1

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

print(top_1(a))
Exemplo n.º 3
0
 def test_top_1(self):
     self.assertListEqual(top_1([1, 1, 2, 2, 3]), [1, 2])
     self.assertListEqual(top_1([1, 2, 3, 324, 234, 23, 23, 1, 23, 23]),
                          [23])
Exemplo n.º 4
0
    def test_top_1(self):

        self.assertListEqual(top_1([20, 37, 20, 21, 37, 21, 21]), [21])
        self.assertListEqual(top_1([1, 1, 2, 2, 3, 4]), [1, 2])