【发布时间】:2014-02-12 01:23:42
【问题描述】:
我有这样的字典:
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 结束的子列表。
【问题讨论】: