此间内容,仅是闲着无聊的情况下顺便记录一点有用的代码而已。所以很短很短。
很简单的,一看就懂。(其实就一句话而已)
def dict_slice(ori_dict, start, end):
"""
字典类切片
:param ori_dict: 字典
:param start: 起始
:param end: 终点
:return:
"""
slice_dict = {k: ori_dict[k] for k in list(ori_dict.keys())[start:end]}
return slice_dict
a = {"1": 1, "2": 2, "3": 3}
print(dict_slice(a, 1, -1))
>>> {'2': 2}
以上,就没了~~