import re


def find_subtype(meta_dict):
    """Find subtype from dictionary of sequence metadata.

    Args:
        `meta_dict` (dict)
        	dictionary of metadata downloaded from genbank

    Returns:
        `subtype` (str)
        	RSV subtype as one letter string, 'A' or 'B'.
    """

    subtype = ''
    if ' A' in meta_dict['organism']:
        subtype = 'A'
    elif ' B' in meta_dict['organism']:
        subtype = 'B'

    elif subtype == '':
        for val in meta_dict.values():
            if re.search(r'RSV\s?A\b', val) or \
                    re.search(r'type: A\b', val) or    \
                    re.search(r'group: A\b', val) or re.search(r'\bA\b', val):
                subtype = 'A'
            elif re.search(r'RSV\s?B\b', val) or \
                    re.search(r'type: B\b', val) or \
                    re.search(r'group: B\b', val) or re.search(r'\bB\b', val):
                subtype = 'B'

    return subtype