import re from typing import List from million.model.message import Message def is_count(message: Message) -> bool: """ Check if the message is a count """ return message.content is not None and bool(re.search('(\d{2,}|^\d$)', message.content)) def retain_counts(messages: List[Message]) -> List[Message]: """ Retain only the messages that have a content """ return [ m for m in messages if is_count(m) ]