From charlesreid1

Map Abstract Data Type

The map abstract data type must support the following basic operations:

  • m[k] or m.get(k) - get the value v associated with key k in map m, returns key error
  • m[k] = v or m.set(k,v) or m.put(k,v) - set the value v associated with key k in map m
  • del m[k] or m.remove(k) - remove the element with key k in map m
  • len(m) or m.size() - return the number of elements (unique keys) in the map
  • iter(m) - iterator over keys of map

Other convenience methods:

  • m.contains(k) or k in m - perform search to see if map m contains key k
  • m.get(k, d=None) - return m[k] if key k exists in the map, otherwise return a default value in place of a key error
  • m.setdefault(k,d) - if key k exists in map, return m[k]. otherwise, set m[k] to default value d and return value
  • m.pop(k, d=None) - remove item associated with key k from map and return associated value v
  • m.popItem() - remove arbitrary key-vlue pair from the map, and return a (k,v) tuple representing the removed pair. raise key error if empty map.
  • m.clear() - remove key-value pairs from map
  • m.keys() - return set-like view of keys
  • m.value() - return set-like view of values
  • m.items() - return set-like view of (k,v) tuples for entries of m
  • m.update(m2) - assign m[k] = v for every (k,v) pair in map m2
  • m.equals(m2) m.compareTo(m2) etc.

Java Variation

Basic operations:

  • size()
  • isEmpty()
  • get(k)
  • put(k,v)
  • remove(k)
  • keySet()
  • values()
  • entrySet()



Flags