same as Ex5, but with dictionaries instead of lists.