Python中二维列表的按元素操作

问题描述 投票:0回答:1

我正在编写脚本以查找三个人的开会时间。我设法以二进制格式获取其忙/闲状态编码,接下来的三天中0空闲,1忙于30分钟。我按天将其状态分为以下字典格式。

print(date_schedule)
{'Monday, 2020-02-03': ['000000000000000000101101001110110000000000000000',
  '000000000000000000001111011100001100000000000000',
  '000000000000000011110100011000110000000000000000'],
 'Tuesday, 2020-02-04': ['000000000000000000100010000000000000000000000000',
  '000000000000000000001111001000110000000000000000',
  '000000000000000011111000111100101000000000000000'],
 'Wednesday, 2020-02-05': ['000000000000000000111000000000000000000000000000',
  '000000000000000001001100110000000000000000000000',
  '000000000000000000111100000001001000000000000000']}

目标:将那些0转换为三十分钟的时间间隔。

For Example: 00:00----00:30
             00:30----01:00
                   ...
             23:30----24:00

尝试:

#Separate the code into a two dimensional list
schedule = date_free.values()

#Append the block to a new list.
free = []
for value in schedule:
   for v in value:
       for idx, time in enumerate(v):
           if time == '0':
                idx = idx/2
                end = idx + 0.5
                #5 slots, and two decimals
                idx = '{:05.2f}'.format(idx).replace('.50','.30').replace('.',':')
                end =  '{:05.2f}'.format(end).replace('.50','.30').replace('.',':')
                free.append((idx + '----' + end))

问题: 免费有372个元素,我不知道如何像以前那样在schedule中使其成为一个二维列表结构(因为数字0每个v都不同)。有没有一种方法可以不创建新列表,而是将上述逻辑元素直接应用于schedule

奖金问题:我还没有到那儿,但是我的下一个目标是找到每天那30个时间段的交点,如下面的random示例所示。如果您有任何建议,请让我知道

print(date_time_final)
{'Monday, 2020-02-03': ['08:00----08:30','09:30----10:00','12:00----12:30'],
'Tuesday, 2020-02-04' : ['09:00----09:30','10:30----11:00','13:00----13:30','14:00----14:30']
'Wednesday, 2020-02-05' : ['07:00----07:30','14:30----15:00','15:00----15:30','19:00----19:30']}

谢谢您的帮助!

string multidimensional-array python-3.6 win32com
1个回答
0
投票

您正在寻找这样的东西吗?

© www.soinside.com 2019 - 2024. All rights reserved.