Chalarangelo/30-seconds-of-python

[BUG] non-keyable values in collect_dictionary snippet

azanbinzahid opened this issue · 2 comments

collect_dictionary snippet it works fine for given example with a key value pair in which a value can be converted into a key. What if the values are of types which cannot be converted to key like a list or obj? The current snippet throws an error for this:

ages = {
    "a": 1,
    "b": [1, 2, 4],
}

It is because a list cannot be converted into a key. I have two solutions:

  1. Edit the same snippet and cater for values of type list and make each list entry a unique key and it's original key as value.
  2. Make a new snippet collect_list_dictionary and cater for values with type list

The snippet clearly states that it only works for hashable values. Therefore this behavior is by design. Closing as wontfix.

Thank you for looking at it. Can I submit a new snippet for non-hashable value?