from django import template

register = template.Library()


@register.filter
def get_item(dictionary, key):
    if isinstance(dictionary, dict):
        return dictionary.get(key)
    try:
        return dictionary[int(key)]
    except (IndexError, KeyError, TypeError, ValueError):
        return None


@register.filter
def split(value, arg):
    return value.split(arg)
