python关于排班的问题

0

import calendar
person=['mary','tom','jimmy','john']
year=2020
month=6

l = list(range(1,calendar.monthrange(year,month)[1]+1))
n = len(person)

z=[dict(zip(person,x)) for x in [l[i:i + n] for i in range(0, len(l), n)]]
print(z)

========================
[{'mary': 1, 'tom': 2, 'jimmy': 3, 'john': 4}, {'mary': 5, 'tom': 6, 'jimmy': 7, 'john': 8}, {'mary': 9, 'tom': 10, 'jimmy': 11, 'john': 12}, {'mary': 13, 'tom': 14, 'jimmy': 15, 'john': 16}, {'mary': 17, 'tom': 18, 'jimmy': 19, 'john': 20}, {'mary': 21, 'tom': 22, 'jimmy': 23, 'john': 24}, {'mary': 25, 'tom': 26, 'jimmy': 27, 'john': 28}, {'mary': 29, 'tom': 30}]

import calendar
person=['mary','tom','jimmy','john']
year=2020
month=6

l = list(range(1,calendar.monthrange(year,month)[1]+1))
n = len(person)

p=[l[i:i + n] for i in range(0, len(l), n)]

z=[dict(zip(person,x)) for x in [l[i:i + n] for i in range(0, len(l), n)]]

temp=None
for i in z:
if temp == None:
temp=i
for key in temp.keys() & i.keys():
if temp[key]==i[key]:
d3=temp
else:
d3[key] = "{},{}".format(temp[key], i[key])
temp = d3

print(d3)

=====================
{'mary': '1,5,9,13,17,21,25,29', 'tom': '2,6,10,14,18,22,26,30', 'jimmy': '3,7,11,15,19,23,27', 'john': '4,8,12,16,20,24,28'}

leemamas | 初学一级 | 园豆：182

0

您需要登录以后才能回答，未注册用户请先注册