Use keyBy in getDictionary

As per the discussion in #4828