I have dictionary like:
item_count_per_section = {1: 3, 2: 5, 3: 2, 4: 2}
这个字典中检索到的项目总数为:
total_items = range(sum(item_count_per_section.values()))
现在我想按照字典的值来转换
total_items
:items_no_per_section = {1: [0,1,2], 2: [3,4,5,6,7], 3:[8,9], 4:[10,11] }
例如,将total_items
序列逐个切片为子列表,这些子列表从先前的“迭代”索引开始,并以初始字典中的value
结束。