def __getitem__(self, key):
def getitem(k, v):<EOL><INDENT>if 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 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))<EOL><DEDENT>except KeyError:<EOL><INDENT>continue<EOL><DEDENT><DEDENT>return tmp<EOL><DEDENT><DEDENT>try:<EOL><INDENT>return self._dict[key]<EOL><DEDENT>except KeyError:<EOL><INDENT>pass<EOL><DEDENT>keys = SmartDict.split_key_pattern.split(key)<EOL>value = self._dict<EOL>for k in keys:<EOL><INDENT>value = getitem(k, value)<EOL><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