src/pylib/builtins/dict

Search:
Group by:
Source   Edit  

Types

PyDictItemView[K; V] = object of PyDictView
  mapping*: PyDict[K, V]
Source   Edit  
PyDictKeyView[T] = object of PyDictView
  mapping*: PyDict[T, auto]
Source   Edit  
PyDictValueView[T] = object of PyDictView
  mapping*: PyDict[auto, T]
Source   Edit  
PyDictView = object of RootObj
Warning: currently mapping attr is dict itself, i.e. modifiable
Source   Edit  

Procs

proc `==`[A, B](self, other: PyDict[A, B]): bool
Source   Edit  
proc `[]`[A, B](t: PyDict[A, B]; key: A): B
Source   Edit  
proc `[]=`[A, B](t: PyDict[A, B]; key: A; val: sink B)
Source   Edit  
proc clear(self: PyDict)
Source   Edit  
proc contains[A, B](t: PyDict[A, B]; key: A): bool
Source   Edit  
func contains[K, V](t: PyDictItemView[K, V]; x: (K, V)): bool
Source   Edit  
func contains[T](t: PyDictKeyView[T]; x: T): bool
Source   Edit  
func contains[T](t: PyDictValueView[T]; x: T): bool
Source   Edit  
func copy[K, V](self: PyDict[K, V]): PyDict[K, V]
Source   Edit  
proc delitem[K, V](self: PyDict[K, V]; k: K)
pysugar expect such a proc to hook del d[k] Source   Edit  
func get[K, V](self: PyDict[K, V]; key: K): V
Source   Edit  
func get[K, V](self: PyDict[K, V]; key: K; default: V): V
Source   Edit  
func items[K, V](self: PyDict[K, V]): PyDictItemView[K, V]
Source   Edit  
func iter[K, V](self: PyDict[K, V]): PyIterator[K]
Source   Edit  
func keys[K, V](self: PyDict[K, V]): PyDictKeyView[K]
Source   Edit  
proc len(self: PyDict): int
dict.__len__ Source   Edit  
proc len(view: SomePyDictView): int
Source   Edit  
func pop[K, V](self: PyDict[K, V]; key: K): V
Source   Edit  
func pop[K, V](self: PyDict[K, V]; key: K; default: V): V
Source   Edit  
func popitem[K, V](self: PyDict[K, V]): (K, V)
Warning: this is currently LILO instead of LIFO
Source   Edit  
func setdefault[K, V](self: PyDict[K, V]; key: K; default = V.default)
Warning: default defaults to V.default instead of None
Source   Edit  
func toPyDict[K, V](x: not openArray[(K, V)] and Iterable[(K, V)]): PyDict[K, V]
Source   Edit  
func toPyDict[K, V](x: openArray[(K, V)]): PyDict[K, V]
Source   Edit  
func values[K, V](self: PyDict[K, V]): PyDictValueView[V]
Source   Edit  
func `|`(a, b: PyDict): PyDict
Python-like merge dict operator, a new dict is created from a and b, keys in the second operand override keys in the first operand Source   Edit  
proc `|=`(a, b: PyDict)
Python-like in-place dict update operator. b is added into a, keys in b override same keys from a Source   Edit  

Iterators

iterator items[K, V](self: PyDict[K, V]): (K, V)
Source   Edit  
iterator iter[K, V](self: PyDict[K, V]): K
Warning: Nim's for stmt calls items implicitly, instead of iter so beware to always write iter for dict in for loop

Example:

let d = dict(a=1)
for i in iter(d):
  assert i == "a"
for i in d:
  assert i[0] == "a" and i[1] == 1
Source   Edit  
iterator keys[K, V](self: PyDict[K, V]): K
Source   Edit  
iterator values[K, V](self: PyDict[K, V]): V
Source   Edit  

Macros

macro dict(kwargs: varargs[untyped]): PyDict
Source   Edit  
macro update(self: PyDict; kws: varargs[untyped])
d.update(**kws) d.update(iterable, **kws) Source   Edit  

Templates

template `$`(self: PyDict): string
Source   Edit  
template `$`(view`gensym1: PyDictKeyView): string
Source   Edit  
template `$`(view`gensym2: PyDictValueView): string
Source   Edit  
template `$`(view`gensym3: PyDictItemView): string
Source   Edit  
template items(view: SomePyDictView): untyped
Source   Edit  
template iter(view: SomePyDictView): untyped
Source   Edit  
template repr(self: PyDict): string {.dirty.}
Source   Edit  
template repr(view`gensym1: PyDictKeyView): string
Source   Edit  
template repr(view`gensym2: PyDictValueView): string
Source   Edit  
template repr(view`gensym3: PyDictItemView): string
Source   Edit