cpython-3.5.0: Bindings for libpython
Safe HaskellNone
LanguageHaskell2010

CPython.Types.Dictionary

Synopsis

Documentation

clear :: Dictionary -> IO () Source #

Empty an existing dictionary of all key-value pairs.

contains :: Object key => Dictionary -> key -> IO Bool Source #

Determine if a dictionary contains key. If an item in the dictionary matches key, return True, otherwise return False. On error, throws an exception. This is equivalent to the Python expression key in d.

copy :: Dictionary -> IO Dictionary Source #

Return a new dictionary that contains the same key-value pairs as the old dictionary.

getItem :: Object key => Dictionary -> key -> IO (Maybe SomeObject) Source #

Return the object from a dictionary which has a key key. Return Nothing if the key is not present.

setItem :: (Object key, Object value) => Dictionary -> key -> value -> IO () Source #

Inserts value into a dictionary with a key of key. key must be hashable; if it isn’t, throws TypeError.

deleteItem :: Object key => Dictionary -> key -> IO () Source #

Remove the entry in a dictionary with key key. key must be hashable; if it isn’t, throws TypeError.

items :: Dictionary -> IO List Source #

Return a List containing all the items in the dictionary, as in the Python method dict.items().

keys :: Dictionary -> IO List Source #

Return a List containing all the keys in the dictionary, as in the Python method dict.keys().

values :: Dictionary -> IO List Source #

Return a List containing all the values in the dictionary, as in the Python method dict.values().

size :: Dictionary -> IO Integer Source #

Return the number of items in the dictionary. This is equivalent to len(d).

merge :: Mapping b => Dictionary -> b -> Bool -> IO () Source #

Iterate over mapping object b adding key-value pairs to a dictionary. b may be a dictionary, or any object supporting keys and getItem. If the third parameter is True, existing pairs in will be replaced if a matching key is found in b, otherwise pairs will only be added if there is not already a matching key.

update :: Mapping b => Dictionary -> b -> IO () Source #

This is the same as (\a b -> merge a b True) in Haskell, or a.update(b) in Python.

mergeFromSeq2 :: Object seq2 => Dictionary -> seq2 -> Bool -> IO () Source #

Update or merge into a dictionary, from the key-value pairs in seq2. seq2 must be an iterable object producing iterable objects of length 2, viewed as key-value pairs. In case of duplicate keys, the last wins if the third parameter is True, otherwise the first wins. Equivalent Python:

def mergeFromSeq2(a, seq2, override):
  for key, value in seq2:
    if override or key not in a:
      a[key] = value

Orphan instances

Concrete Dictionary Source # 
Instance details