|
发表于 2021-2-3 09:43:13
From FishC Mobile
|
显示全部楼层
|阅读模式
10鱼币
…
blocks = {'itemName': 'minecraft:glass', 'auxValue': 0}
blockSet = set(blocks.items())
playItemList = [{'itemId': 395, 'count': 1, 'enchantData': [], 'durability': 0, 'customTips': '', 'extraId': '', 'modId': '', 'modItemId': '', 'itemName': 'minecraft:glass', 'auxValue': 0, 'showInHand': True},
{'itemId': 806, 'count': 1, 'enchantData': [], 'durability': 15, 'customTips': '', 'extraId': '', 'modId': '', 'modItemId': '', 'itemName': 'lbmod_builder_wands:lb_item_wand_stone', 'auxValue': 0, 'showInHand': True},
None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None]
for playItemDict in playItemList:
print type(playItemDict)
playItemSet = set(playItemDict.items())
if not(playItemDict == None):
if blockSet.issubset(playItemSet):
print "背包里有此方块"
…
playItemDict明明是字典类型,为什么playItemSet = set(playItemDict.items())为什么报错为列表?
本帖最后由 逃兵 于 2021-2-3 11:19 编辑
列表是可以的,但是里面嵌套另一个列表就不行了 >>> temp = [1,2,3]
>>> set(temp)
{1, 2, 3}
>>> temp = [[1,2],[3,4]]
>>> set(temp)
Traceback (most recent call last):
File "<pyshell#28>", line 1, in <module>
set(temp)
TypeError: unhashable type: 'list'
>>> temp = [1,[]]
>>> set(temp)
Traceback (most recent call last):
File "<pyshell#30>", line 1, in <module>
set(temp)
TypeError: unhashable type: 'list'
>>> temp = [(1,2),(3,4)]
>>> set(temp)
{(1, 2), (3, 4)}
>>> temp = [(1,2),[3,4]]
>>> set(temp)
Traceback (most recent call last):
File "<pyshell#34>", line 1, in <module>
set(temp)
TypeError: unhashable type: 'list'
|
|