import re


def is_snake_case(id_name):
    """Check if id_name is written in snake case.

    Actually, it is restricted to a certain subset of snake case, so that
    we can guarantee camel->snake->camel roundtrip.

    >>> is_snake_case('')
    False
    >>> is_snake_case('_')
    False
    >>> is_snake_case('h')
    True
    >>> is_snake_case('hello_world')
    True
    >>> is_snake_case(' hello_world ')
    False
    >>> is_snake_case('_hello')
    False
    >>> is_snake_case('hello_')
    False
    >>> is_snake_case('__hello_world__')
    False
    >>> is_snake_case('_hello6_wor7d_')
    False
    >>> is_snake_case('hello6_wor7d')
    True
    >>> is_snake_case('hello__world')
    False
    >>> is_snake_case('hello-world')
    False
    >>> is_snake_case('HelloWorld')
    False
    >>> is_snake_case('ab6')
    True
    >>> is_snake_case('ab_6')
    False
    >>> is_snake_case('6_ab')
    False
    >>> is_snake_case('ab_6_ab6')
    False
    """

    snake_case_re = re.compile(r"""
            [a-z][a-z0-9]*      # first word is required, start w/ alpha
            (_[a-z][a-z0-9]*)*  # any number of words follow
            $
            """, re.VERBOSE)

    return snake_case_re.match(id_name) is not None