<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _group_flat_tags(tag, tags):
 """Extract tags sharing the same name as the provided tag. Used to collect options for radio and checkbox inputs. :param Tag tag: BeautifulSoup tag :param list tags: List of tags :return: List of matching tags """

    grouped = [tag]
    name = tag.get('name', '').lower()
    while tags and tags[0].get('name', '').lower() == name:
        grouped.append(tags.pop(0))
    return grouped