def get_value(record, key, default=None):
def getitem(k, v, default):<EOL><INDENT>if isinstance(v, string_types):<EOL><INDENT>raise KeyError<EOL><DEDENT>elif isinstance(v, dict):<EOL><INDENT>return v[k]<EOL><DEDENT>elif '<STR_LIT:]>' in k:<EOL><INDENT>k = k[:-<NUM_LIT:1>].replace('<STR_LIT:n>', '<STR_LIT>')<EOL>try:<EOL><INDENT>return v[int(k)]<EOL><DEDENT>except IndexError:<EOL><INDENT>return default<EOL><DEDENT>except ValueError:<EOL><INDENT>return v[slice(*map(<EOL>lambda x: int(x.strip()) if x.strip() else None,<EOL>k.split('<STR_LIT::>')<EOL>))]<EOL><DEDENT><DEDENT>else:<EOL><INDENT>tmp = []<EOL>for inner_v in v:<EOL><INDENT>try:<EOL><INDENT>tmp.append(getitem(k, inner_v, default))<EOL><DEDENT>except KeyError:<EOL><INDENT>continue<EOL><DEDENT><DEDENT>return tmp<EOL><DEDENT><DEDENT>if isinstance(record, list):<EOL><INDENT>record = {'<STR_LIT>': record}<EOL>key = '<STR_LIT:.>'.join(['<STR_LIT>', key])<EOL><DEDENT>try:<EOL><INDENT>return record[key]<EOL><DEDENT>except KeyError:<EOL><INDENT>pass<EOL><DEDENT>keys = SPLIT_KEY_PATTERN.split(key)<EOL>value = record<EOL>for k in keys:<EOL><INDENT>try:<EOL><INDENT>value = getitem(k, value, default)<EOL><DEDENT>except KeyError:<EOL><INDENT>return default<EOL><DEDENT><DEDENT>return value<EOL>
Return item as `dict.__getitem__` but using 'smart queries'.

    .. note::

        Accessing one value in a normal way, meaning d['a'], is almost as
        fast as accessing a regular dictionary. But using the special
        name convention is a bit slower than using the regular access:
        .. code-block:: python
            >>> %timeit x = dd['a[0].b']
            100000 loops, best of 3: 3.94 us per loop
            >>> %timeit x = dd['a'][0]['b']
            1000000 loops, best of 3: 598 ns per loop