2015-10-19 146 views
1

,所以我得到一本字典,看起来像这样:计数日历周,并将它们存储到一个数组与.isocalendar

{2321: datetime.datetime(2015, 2, 16, 11, 55, 50, 414175, tzinfo=<LocalTimezone "UTC+01:00" 1:00:00>), 
2322: datetime.datetime(2015, 2, 16, 13, 10, 17, 338086, tzinfo=<LocalTimezone "UTC+01:00" 1:00:00>), 
2323: datetime.datetime(2015, 2, 16, 13, 12, 30, 847941, tzinfo=<LocalTimezone "UTC+01:00" 1:00:00>), 
2324: datetime.datetime(2015, 2, 16, 13, 15, 14, 803438, tzinfo=<LocalTimezone "UTC+01:00" 1:00:00>), 
2325: datetime.datetime(2015, 2, 16, 13, 17, 42, 749529, tzinfo=<LocalTimezone "UTC+01:00" 1:00:00>), 
2326: datetime.datetime(2015, 2, 16, 13, 19, 58, 757024, tzinfo=<LocalTimezone "UTC+01:00" 1:00:00>), 
2327: datetime.datetime(2015, 2, 16, 13, 22, 16, 554052, tzinfo=<LocalTimezone "UTC+01:00" 1:00:00>), 
2328: datetime.datetime(2015, 2, 16, 13, 26, 56, 4452, tzinfo=<LocalTimezone "UTC+01:00" 1:00:00>), 
2081: datetime.datetime(2015, 1, 27, 10, 28, 10, 695887, tzinfo=<LocalTimezone "UTC+01:00" 1:00:00>), 
2082: datetime.datetime(2015, 1, 27, 10, 35, 34, 71091, tzinfo=<LocalTimezone "UTC+01:00" 1:00:00>), 
2083: datetime.datetime(2015, 1, 27, 10, 40, 1, 436955, tzinfo=<LocalTimezone "UTC+01:00" 1:00:00>)} 

其{ticketID:ticketDateTime}

我想使用.isocalendar从DateTime对象中获取日历周期(因为我需要为每周计算门票)

我想过创建一个长度为52(因为一年有52周)的零填充数组,然后迭代带有forloop的字典,并且总是为索引o添加1 f这个日历周。

对不起,我在新的蟒蛇,并会尝试向你展示在C#中的一些代码,我怎么想它可以工作:

int[] resultsArray = new int[52] 

for(int i = 0; i<= myDictionary.Length; i++){ 
index = myDictionary[i].isocalendar()[1] 
resultsArray[index] = resultsArray[index]+1} 

回答

0

试试这个:

ClosedList = [0] * 53 
OpenList = [0] * 53 
OpenedList = [0] * 53 
def CreateKWlist(): 
for i in ClosedDict: 
    for j,k in ClosedDict[i]['prio-events']: 
     if j.isocalendar()[0] == 2015: 
      index = j.isocalendar()[1] 
      ClosedList[index] += 1 
      OpenedList[index] += 1 
      break 
for i in OpenDict: 
    for j,k in OpenDict[i]['prio-events']: 
     if j.isocalendar()[0] == 2015: 
      index = j.isocalendar()[1] 
      OpenList[index] += 1 
      OpenedList[index] += 1 
      break 
相关问题