2015-10-19 65 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 
相關問題