2014-01-09 20:00:20 -05:00
|
|
|
d = {1: 2}
|
|
|
|
for m in d.items, d.values, d.keys:
|
|
|
|
print(m())
|
|
|
|
print(list(m()))
|
|
|
|
|
2016-10-16 20:43:47 -04:00
|
|
|
# print a view with more than one item
|
|
|
|
print({1:1, 2:1}.values())
|
|
|
|
|
|
|
|
# unsupported binary op on a dict values view
|
|
|
|
try:
|
|
|
|
{1:1}.values() + 1
|
|
|
|
except TypeError:
|
|
|
|
print('TypeError')
|
|
|
|
|
|
|
|
# unsupported binary op on a dict keys view
|
|
|
|
try:
|
|
|
|
{1:1}.keys() + 1
|
|
|
|
except TypeError:
|
|
|
|
print('TypeError')
|
|
|
|
|
2023-01-18 14:59:54 -05:00
|
|
|
# keys dict_view is not hashable
|
|
|
|
|
|
|
|
try:
|
|
|
|
hash({}.keys())
|
|
|
|
except TypeError:
|
|
|
|
print('TypeError')
|
|
|
|
|
|
|
|
# values dict_view is hashable
|
|
|
|
|
|
|
|
print(type(hash({}.values())))
|
|
|
|
|
|
|
|
# items dict_view is not hashable
|
|
|
|
|
|
|
|
try:
|
|
|
|
hash({}.items())
|
|
|
|
except TypeError:
|
|
|
|
print('TypeError')
|
|
|
|
|
2014-01-09 20:00:20 -05:00
|
|
|
# set operations still to come
|