4 ms·
Not impressed. I downloaded the python book, chose a section at random (chapter 15: dictionaries), and found an error on the first thing I looked at. The book
by cabalamat 9y ago
Not impressed. I downloaded the python book, chose a section at random (chapter 15: dictionaries), and found an error on the first thing I looked at.
The book says that:
d=dict(**otherDict)
only works if otherDict's keys are strings, but in reality it also works if the keys are integers:
>>> dict(**{1:2,3:4})
{1: 2, 3: 4}
- tsuraan 9y agoLooks like a 2 vs 3 thing: Python 2.7.14 (default, Jan 6 2018, 14:37:03) [GCC 5.4.0] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> dict(**{1:2,3:4}) {1: 2, 3: 4} >>> vs Python 3.4.5 (default, Jan 6 2018, 14:44:12) [GCC 5.4.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> dict(**{1:2,3:4}) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: keyword arguments must be strings >>>
- happy-go-lucky 9y agoThis works in Python 3.6: >>> {**{1:2,3:4}} {1: 2, 3: 4} :)
- tomc1985 9y agoSomewhat unrelated, but hte first concern that popped into my head is how the information contained ties to specific version of its subject? Like, the Python book looks awesome but I have to use Python 2.7 day-to-day (don't ask). Are Python 2/3 stuff clearly marked?