像这样的工作:days = 7 weeks = 4schedule = [(d+ w%2)%days + int((d+w%2)>(days-1)) for w in range(weeks) for d in range(days)]`这实质上是说,如果这是一个奇数周(w%2 = 1),则在正常时间表中添加一个并且不允许最后一天等于 0,这就是我添加 int((d+w%2 )>(days-1)) 期限。
检查迭代变量是偶数还是奇数,并将适当的列表附加到结果中。result = []for i in range(5): if i % 2 == 0: result += list(range(7)) else: result += list(range(1, 7)) + [1]print(result)