def hyphen_range(s, first=None, last=None):
    """ creates a list with each integer from a complex range string like "1-9,12, 15-20,23".
        The wildcard '*' returns [first, last+1].

    >>> list(hyphen_range('1-9,12, 15-20,23'))
    [1, 2, 3, 4, 5, 6, 7, 8, 9, 12, 15, 16, 17, 18, 19, 20, 23]

    >>> list(hyphen_range('1-9,12, 15-20,2-3-4'))
    Traceback (most recent call last):
        ...
    ValueError: format error in 2-3-4
    """
    res = []
    if s == '*':
        if first is None or last is None:
            raise ValueError(
                'Wildcard range requires first and last of index list')
        res = list(range(first, last + 1))
    else:
        for x in s.split(','):
            elem = x.split('-')
            if len(elem) == 1:
                res.append(int(elem[0]))
            elif len(elem) == 2:
                start, end = map(int, elem)
                for i in range(start, end + 1):
                    res.append(i)
            else:
                raise ValueError('format error in %s' % x)
    return res
