I get what seemed to be a weird error for me when I wanted to access to a single element of a tuple
in dict
.
Here the following dict
object:
>>> x = {"palermo":{"country":"ARG",
... "utc":-3,
... "apply_time_change":(False), #other dicts are (True , "Region of the world")
... "hemisphere":"S"
... }}
>>> x['palermo']['apply_time_change'][0]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'bool' object is not subscriptable
What a surprise, but when I checked the object:
>>> x['palermo']
{'country': 'ARG', 'utc': -3, 'apply_time_change': False, 'hemisphere': 'S'}
The tuple
disappeared. It unwrapped. I wondered if it was a new functionality in python 3 to unwrap alone element of an iterable when in a dict
but it is not the case because with list
it keeps the alone element in it. Why ? What's the goal of it ? Because for me it just generates a bug.
Python 3.7.4 under Ubuntu 18.04.3