M13) Collections as dictionary keys

A dictionary stores route labels using keys that describe city names. Listing 1 defines four candidate keys: a tuple, a list, a set, and a tuple containing a list.

Listing 1: Four collections containing city names.
pair = ("Enschede", "Utrecht")
stops = ["Enschede", "Utrecht"]
cities = {"Enschede", "Utrecht"}
group = ("Enschede", ["Utrecht"])

Which candidates can be used directly as a dictionary key, without converting them to another type? Consider each candidate separately.

  • pair and group only.
  • pair only.
  • stops and cities only.
  • All four candidates.