def getOrElseUpdate(dictionary, key, opr):
  """If given key is already in the dictionary, returns associated value.
  Otherwise compute the value with opr, update the dictionary and return it.
  None dictionary are ignored.

    >>> d = dict()
    >>> getOrElseUpdate(d, 1, lambda _: _ + 1)
    2
    >>> print(d)
    {1: 2}

  @type  dictionary: dictionary of A => B
  @param dictionary: the dictionary
  @type  key: A
  @param key: the key
  @type  opr: function of A => B
  @param opr: the function to compute new value from keys
  @rtype: B
  @return: the value associated with the key
  """
  if dictionary is None:
    return opr(key)
  else:
    if key not in dictionary:
      dictionary[key] = opr(key)
    return dictionary[key]