Top 2 most common elements inside array in Python
If you're okay with using the built-in collections module, I'd suggest the following. collections.Counter is ideally suited for this and will make the problem trivial.

from collections import Counter


def top_k(numbers, k=2):
    """The counter.most_common([k]) method works
    in the following way:
    &gt;&gt;&gt; Counter('abracadabra').most_common(3)  
    [('a', 5), ('r', 2), ('b', 2)]
    """

    c = Counter(numbers)
    most_common = [key for key, val in c.most_common(k)]

    return most_common


Without using the built-in collections module, the following will work:

def top_k_nobuiltin(numbers, k=2):
    # The first part is identical to your implementation and works just
    # fine
    counter = {}
    for number in numbers:
        if number in counter:
            counter[number] += 1
        else:
            counter[number] = 1

    # The line below creates an iterator that will generate the
    # sequence [(4, 3), (3, 2), (5, 1), (1, 1)], i.e.
    # count the occurrence for each value.
    # In particular, sorted() with key=lambda kv: kv[1] will turn
    # a dictionary into a list of tuples, sorted by the second item
    # of each tuple

    sorted_by_value = reversed(sorted(counter.items(), key=lambda kv: kv[1]))

    top_vals = [item[0] for item in sorted_by_value][:k]

    return top_vals 


For both cases, you'll get the desired result:

def main():
    nums = [1, 4, 3, 4, 5, 3, 4]  # [4,3]

    print(top_k(nums))  # [4,3]
    print(top_k_nobuiltin(nums))  # [4,3]    

if __name__ == '__main__':
    main()