Is there a way to get a dict comprehension to raise an exception if it would override a key?
For example, I would like the following to error because there are two values for the key 'a'
:
>>> {k:v for k, v in ('a1', 'a2', 'b3')}
{'a': '2', 'b': '3'}
I realise this can be done with a for
loop. Is there a way to do it while keeping the comprehension syntax?