from typing import Union


def count_even(obj: Union[list, int]) -> int:
    """
    Return the number of even numbers in obj or sublists of obj
    if obj is a list.  Otherwise, if obj is a number, return 1
    if it is an even number and 0 if it is an odd number.

    >>> count_even(3)
    0
    >>> count_even(16)
    1
    >>> count_even([1, 2, [3, 4], 5])
    2
    """
    # counter = 0
    # # case case:
    # if isinstance(obj, int):
    #     if obj % 2 == 0:
    #         counter += 1
    # else:
    #     # obj is a list.
    #     for item in obj:
    #         # item is either an int or another list.
    #         counter += count_even(item)
    # return counter

    # with listcomp and ternary...
    if isinstance(obj, int):
        return 1 if obj % 2 == 0 else 0
    return sum(count_even(item) for item in obj)