Add doctest for IdDict with example (#38881)
This came up from a Slack discussion and was based on a surprising [Python behavior](https://twitter.com/DahlitzF/status/1338384990040682498).
@haampie provided the example and I thought the docstrings could help out another beginner to understand why a different data structure is justified.