File: automaton_get.rst

package info (click to toggle)
python-pyahocorasick 1.4.1-2.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 768 kB
  • sloc: ansic: 4,552; python: 2,823; sh: 312; makefile: 242
file content (27 lines) | stat: -rw-r--r-- 683 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
get(key[, default])
----------------------------------------------------------------------

Return the value associated with the key string.

Raise a ``KeyError`` exception if the key is not in the trie and no default is provided.

Return the optional default value if provided and the key is not in the trie.

Example
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. code:: python

    >>> import ahocorasick
    >>> A = ahocorasick.Automaton()
    >>> A.add_word("cat", 42)
    True
    >>> A.get("cat")
    42
    >>> A.get("dog")
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    KeyError
    >>> A.get("dog", "good dog")
    'good dog'