【发布时间】:2020-11-26 18:22:03
【问题描述】:
我有两个列表。第一个名为 location,其长度可以从 1 到无穷大不等。
location = ['loc1,'loc2','loc3','loc4,'loc5','loc6','loc7,'loc8','loc9','loc10,'loc11','loc12','loc13,'loc14','loc15','loc16,'loc17','loc18','loc19,'loc20','loc21','loc22,'loc23','loc24','loc25','loc26','loc27',] <- Please note that length could from 1 to infinite number
第二个列表名为 auditor 。它的长度通常大于 location 列表长度。如果甚至没有将第一个或最后一个审核员分配到其他位置,我想将所有审核员平均分配到这些位置。
auditor = ['aone','atwo','athree','afour','afive','asix','aseven','aeight','anine','aten','aeleven','atwelve','athirteen','afourteen','afitheen','asixteen,'aseventeen''] <- Please note that length could from 1 to infinite number
下面的代码在大多数情况下都很好用,但是当位置为 28 且审核员为 17 时它会失败
df2['location'] = location
df2['auditor'] = [auditor[int(df2)] for df2 in np.arange(0, len(auditor), (len(auditor)/len(df2)))]
我想要的输出是获得最可能的均匀划分列表,并且它必须在任何情况下都有效,只要位置大于审计员。
My_desired_output = '一个', '一个' '两个', '两个', '三', '三', '四', '四', '五', '五', '六', '六', '七', '七', '八', '八', '安宁', '安宁', '吃', '吃', '十一', '十一', '十二点', “十三”, '十四', '十五', '十六', '十七']
【问题讨论】:
-
在您的示例中,位置 > 审核员。代码适用于 ?