我是python编程的新手。我正在尝试制作一个程序,作为天际药水效果的交互式词典,以练习编码拼写检查功能。
这是我代码的相关部分。
effects = {'curedisease' : ['Charred Skeever Hide', 'Felsaad Tern Feathers', 'Hawk Feathers', 'Mudcrab Chitin', 'Vampire Dust'], 'damagehealth' : ['Crimson Nirnroot', 'Deathbell', 'Ectoplasm', 'Emperor Parasol Moss', 'Falmer Ear', 'Human Flesh', 'Human Heart', 'Imp Stool', 'Jarrin Root', 'Nightshade', 'Nirnroot', 'Poison Bloom', 'Red Mountain Flower', 'River Betty', 'Skeever Tail', 'Small Antlers', 'Troll Fat', 'Void Salts'], 'damagemagicka' : ['Butterfly Wing',' Chaurus Eggs', 'Daedra Heart', 'Eye of Sabre Cat', 'Glow Dust', 'Hagraven Feathers', 'Hanging Moss', 'Human Heart', 'Jarrin Root', 'Luna Moth Wing', "Namira's Rot", 'Nordic Barnacle', 'Trama Root'], 'damageMagikaregen' : ['Bear Claws', 'Blue Butterfly Wing', 'Blue Mountain Flower', 'Chicken\'s Egg', 'Glow Dust', 'Hanging Moss', 'Human Heart', 'Jarrin Root', 'Nightshade', 'Spider Egg', 'Spriggan Sap'], 'damagestamina' : ['Blisterwort', 'Blue Butterfly Wing', 'Bone Meal', 'Canis Root', 'Crimson Nirnroot', 'Cyrodilic Spadetail', 'Giant\'s Toe', 'Jarrin Root', 'Nirnroot', 'Rock Warbler Egg', 'Spider Egg'], 'damagestaminasegen' : ['Creep Cluster', 'Daedra Heart', 'Frost Mirriam', 'Giant\'s Toe', 'Histcarp', 'Juniper Berries', 'Large Antlers', 'Silverside Perch', 'Skeever Tail', 'Wheat'], 'fear' : ['Blue Dartwing', 'Cyrodilic Spadetail', 'Daedra Heart', 'Namira\'s Rot', 'Powdered Mammoth Tusk'], 'fortifyalteration' : ['Grass Pod', 'River Betty', 'Spriggan Sap'], 'fortifybarter' : ['Butterfly Wing', 'Dragon\'s Tongue', 'Hagraven Claw', 'Tundra Cotton'], 'fortifyblock' : ['Bleeding Crown', 'Briar Heart', 'Honeycomb', 'Pearl', 'Slaughterfish Scales', 'Tundra Cotton'], 'fortifycarryWeight' : ['Creep Cluster', 'Giant\'s Toe', 'Hawk Beak', 'River Betty', 'Scaly Pholiata', 'Wisp Wrappings'], 'fortifyconjuration' : ['Blue Butterfly Wing', 'Blue Mountain Flower', 'Bone Meal', 'Frost Salts', 'Hagraven Feathers', 'Lavender'], 'fortifydestruction' : ['Beehive Husk', 'Ectoplasm', 'Glow Dust', 'Glowing Mushroom', 'Nightshade', 'Wisp Wrappings'], 'fortifyenchanting' : ['Blue Butterfly Wing', 'Hagraven Claw', 'Snowberries', 'Spriggan Sap'], 'fortifyhealth' : ['Bear Claws', 'Blue Mountain Flower', 'Giant\'s Toe', 'Glowing Mushroom', 'Hanging Moss', 'Wheat'], 'fortifyheavyarmor' : ['Ice Wraith Teeth', 'Sabre Cat Tooth', 'Slaughterfish Scales', 'Thistle Branch', 'White Cap'], 'fortifyillusion' : ['Dragon\'s Tongue', 'Dwarven Oil', 'Mora Tapinella', 'Scaly Pholiata', 'Taproot'], 'fortifylightarmor' : ['Ice Wraith Teeth', 'Sabre Cat Tooth', 'Slaughterfish Scales', 'Thistle Branch', 'White Cap'], 'fortifylockpicking' : ['Falmer Ear', 'Namira\'s Rot', 'Pine Thrush Egg', 'Spider Egg'], 'fortifymagicka ' : ['Briar Heart', 'Ectoplasm', 'Histcarp', 'Jazbay Grapes', 'Red Mountain Flower', 'Tundra Cotton', 'Void Salts'], 'fortifymarksman' : ['Canis Root', 'Elves Ear', 'Juniper Berries', 'Spider Egg'], 'fortifyonehanded' : ['Bear Claws', 'Canis Root', 'Hanging Moss', 'Hawk Feathers', 'Rock Warbler Egg', 'Small Pearl'], 'fortifypickpocket' : ['Blue Dartwing', 'Nordic Barnacle', 'Orange Dartwing', 'Slaughterfish Egg'], 'fortifyrestoration' : ['Abecean Longfin', 'Cyrodilic Spadetail', 'Salt Pile', 'Small Antlers', 'Small Pearl'], 'fortifysmithing' : ['Blisterwort', 'Glowing Mushroom', 'Sabre Cat Tooth', 'Spriggan Sap'], 'fortifysneak' : ['Abecean Longfin', 'Beehive Husk', 'Frost Mirriam', 'Hawk Feathers', 'Human Flesh', 'Powdered Mammoth Tusk', 'Purple Mountain Flower'], 'fortifystamina' : ['Chaurus Eggs', 'Garlic', 'Large Antlers', 'Lavender', 'Slaughterfish Egg', 'Torchbug Thorax'], 'lingeringdamagehealth' : ['Imp Stool', 'Mora Tapinella', 'Orange Dartwing', 'Slaughterfish Egg', 'Slaughterfish Scales'], 'lingeringdamagemagicka' : ['Hagraven Claw', 'Purple Mountain Flower', 'Swamp Fungal Pod', 'Torchbug Thorax', 'Wheat'], 'lingeringdamagestamina' : ['Butterfly Wing', 'Chicken\'s Egg', 'Nightshade', 'Small Antlers'], 'paralysis' : ['Briar Heart', 'Canis Root', 'Human Flesh', 'Imp Stool', 'Swamp Fungal Pod'], 'ravagehealth' : ['Cyrodilic Spadetail', 'Eye of Sabre Cat', 'Giant Lichen', 'Jazbay Grapes', 'Silverside Perch', 'Skeever Tail'], 'ravagemagicka' : ['Frost Mirriam', 'Grass Pod', 'Lavender', 'Orange Dartwing', 'Red Mountain Flower', 'White Cap'], 'ravagestamina' : ['Bee', 'Bone Meal', 'Deathbell', 'Honeycomb', 'Thistle Branch'], 'regeneratehealth' : ['Garlic', 'Juniper Berries', 'Luna Moth Wing', 'Namira\'s Rot', 'Nordic Barnacle', 'Vampire Dust'], 'regeneratemagicka' : ['Dwarven Oil', 'Fire Salts', 'Garlic', 'Jazbay Grapes', 'Moon Sugar', 'Salt Pile', 'Taproot'], 'regeneratestamina' : ['Bee', 'Fly Amanita', 'Mora Tapinella', 'Scaly Pholiata'], 'resistfire' : ['Bone Meal', 'Dragon\'s Tongue', 'Elves Ear', 'Fire Salts', 'Fly Amanita', 'Mudcrab Chitin', 'Snowberries'], 'resistfrost' : ['Frost Mirriam', 'Frost Salts', 'Hawk Beak', 'Moon Sugar', 'Purple Mountain Flower', 'Silverside Perch', 'Slaughterfish Scales', 'Small Pearl', 'Snowberries', 'Thistle Branch'], 'resistmagic' : ['Bleeding Crown', 'Chicken\'s Egg', 'Crimson Nirnroot', 'Hagraven Claw', 'Lavender', 'Nirnroot', 'Tundra Cotton', 'Void Salts', 'Wisp Wrappings'], 'resistpoison' : ['Beehive Husk', 'Charred Skeever Hide', 'Falmer Ear', 'Garlic', 'Grass Pod', 'Mudcrab Chitin', 'Slaughterfish Egg', 'Thistle Branch', 'Troll Fat'], 'resistshock' : ['Blue Dartwing', 'Glow Dust', 'Glowing Mushroom', 'Hawk Beak', 'Pearl', 'Pine Thrush Egg', 'Snowberries', 'Swamp Fungal Pod'], 'restorehealth' : ['Blisterwort', 'Blue Dartwing', 'Blue Mountain Flower', 'Butterfly Wing', 'Charred Skeever Hide', 'Daedra Heart', 'Eye of Sabre Cat', 'Imp Stool', 'Rock Warbler Egg', 'Swamp Fungal Pod', 'Wheat'], 'restoremagicka ' : ['Briar Heart', 'Creep Cluster', 'Dwarven Oil', 'Ectoplasm', 'Elves Ear', 'Fire Salts', 'Frost Salts', 'Giant Lichen', 'Grass Pod', 'Human Flesh', 'Moon Sugar', 'Mora Tapinella', 'Pearl', 'Red Mountain Flower', 'Taproot', 'Vampire Dust', 'White Cap']}
effectslist = effects.keys()
print (effectslist)
麻烦的是,effectslist不会包含字典效果中的所有键。我不清楚它是否一直遗漏相同的键或循环列表,但我需要它来创建一个完整的字符串,用作效果字典中的键。
有人可以向我解释为什么它没有制作完整的清单以及我可以做些什么来创建完整的清单?
谢谢
答案 0 :(得分:1)
麻烦的是,effectslist不会包含字典效果中的所有键。
实际上,没有。它确实包含所有键。
首先,keys()
返回正确数量的元素:
>>> len(effects)
44
>>> len(effects.keys())
44
其次,它返回的所有元素都是唯一的:
>>> len(set(effects.keys()))
44
最后,每个返回的密钥都出现在字典中:
>>> all(k in effects for k in effects.keys())
True
如果你试图找到.keys()
未归还的特定密钥,我相信你会发现它没有。{/ p>
答案 1 :(得分:1)
我自己运行代码,看起来是len(effects)==len(effectslist)
,因此所有帐户都会返回完整列表。是什么让你觉得它没有返回完整列表?请记住,字典不存在于固定顺序中 - 因此当您查询键时,它们的顺序与输入的顺序不同。