title: How to split a list with date, into weekly partition
body: <p>I have a csv file with a collection of tweets. I would like to split my collection into weekly partition. All of my tentatives for use the for cycle's terminate with a cycle loop, python works but it don't want to finish. Someone can explain to me which is my error? I have also tried to make a while cycle (while sortr != '') without luck:</p>
  
  <pre><code>import csv
  from datetime import datetime, timedelta
  from collections import defaultdict
  
  csv1 = open('../archiviato.csv', 'r')
  tabula=csv.reader(csv1)
  sortr= sorted(tabula)
  delta_days = 7
  c = 1
  months= defaultdict(list)
  weeke=defaultdict(list)
  weeks = []
  
  
  
  for j in sortr:
      tweetID = j[0]
      timestamp = j[2]
      times = datetime.strptime(timestamp, "%Y-%m-%d %H:%M:%S")
      trmonth = times.month
      trime = times.day
      months[trmonth].append(j)
      for i in sortr:
          tweetID2 = i[0]
          timestamp2 = i[2]
          times2 = datetime.strptime(timestamp, "%Y-%m-%d %H:%M:%S")
          trime2 = times2.day
          if tweetID != tweetID2 and timedelta(trime2 - trime) &lt;= timedelta(days = delta_days):
              if weeks == []:
                  a = i,j
                  c = 1
                  weeks.append(a)
                  weeke=[c].append(a)
                  print tweetID
                  print tweetID2
              else:
                  c = 1
                  weeke=[c].append(i)
                  print tweetID2
          else:
              c+=1
              j = i
              weeks = []
              continue
  </code></pre>