def get_messages_per_minutes(msgs, minutes):
    """Gets lists of messages for each interval in minutes.

    Args:
        msgs (list of MyMessage objects): Messages.
        minutes (int): The number of minutes in one interval.

    Returns:
        A dictionary such as:
            {
                minute: list off all messages sent within interval [minute, minute + minutes).
            }
    """
    res = {i: [] for i in range(0, 24 * 60, minutes)}
    for msg in msgs:
        res[(msg.date.hour * 60 + msg.date.minute) // minutes * minutes].append(msg)
    return res