from functools import reduce
from random import Random

rand = Random()


def is_not_emtpy(l: list) -> bool:
    """
    Check whether the list is not empty
    :param l: The list
    :return:
    """
    return l is not None and len(l) != 0


def is_emtpy(l: list) -> bool:
    """
    Check whether the list is empty
    :param l: The list
    :return:
    """
    return not is_not_emtpy(l)


def get_random(l: list):
    """
    Gets random element from list
    :param l: The list
    :return: The random element in list
    """
    if len(l) == 0:
        return None
    return l[rand.randint(0, len(l) - 1)]


def for_each(l: list, func):
    for i in l:
        func(i)


def partition(l: list, num: int) -> list:
    return [l[i:i + num] for i in range(0, len(l), num)]


def flatten(l: list) -> list:
    return reduce(list.__add__, l)
