我正在尝试从字典中的某个点拆分字典。似乎做一个简单的 items_dict[3:] 会起作用,但它没有起作用。
items_dict = {
"Cannon barrels":10,
"Cannon furnace":12,
"Candle":36,
"Bronze arrowheads":39,
"Iron arrowheads":40,
"Steel arrowheads":41,
"Mithril arrowheads":42,
"Adamant arrowheads":4
}
print items_dict[3:] # Nope, this won't work
print items_dict["Candle"] # This will of course, but only returns the Candle's number
我只知道如何 to slice a dictionary by keys that start with a certain string , 但我只想知道如何对类似于列表的字典进行切片。
请您参考如下方法:
字典是没有顺序的,所以你不能从某个点开始拆分。查看那里的字典,您无法提前知道第一个元素是什么。
