Indexing the ValuesView of a sorteddict
-
18-06-2021 - |
Domanda
Given the documentation, what is wrong with the following code:
import blist
d = blist.sorteddict({3: "first", 7: "second"})
print(d.keys()[1])
print(d.values()[1])
print(d.items()[1])
which prints
Traceback (most recent call last):
File "test.py", line 4, in <module>
print(d.values()[1])
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/_sorteddict.py", line 53, in __getitem__
key = self._mapping.sortedkeys[index]
AttributeError: 'sorteddict' object has no attribute 'sortedkeys'
Soluzione
It seems to be a bug. The code is ok.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow