from typing import List from datetime import date, datetime def find_category (categories, slug): for (category, articles) in categories: if category.slug == slug: return (category, articles) return (None, None) def get_category_articles (categories, slug): category, articles = find_category(categories, slug) if category: return articles else: return [] def display_if_set (value, label): if value: if isinstance(value, (list, tuple)): value = ', '.join(value) if isinstance(value, (date)): value = date.strftime(value, '%d-%m-%Y') if isinstance(value, (datetime)): value = date.strftime(value, '%d-%m-%Y %H:%i') return '