title: Convert a time-range (e.g., 1230-2P) in python to pre-assigned list of bins?
body: <p>I'm writing a course scheduling algorithm for myself using python.</p>
  <p>I was having a lot of trouble working directly with time, so I decided to create &quot;bins&quot; representing each possible half-hour increment in the day. (For example, Monday, 8-830A is 1, while Wednesday 9-930A is 63 and Sunday 6-630P is 195.)</p>
  <p>Each room is given a list of all of the bins in the week (which, for my scheduling hours, is 1-203 representing each day, Monday-Sunday, 8A-10P).</p>
  <p>Then I just loop through each course to see if its requested &quot;bins&quot; are available in a certain room: If they are, I assign the course to that room (not implemented yet) and remove those bins from the room (so that I won't double book anything).</p>
  <p>So far the proof of concept is working fine when I do it manually (e.g., Physics 101 is 1,2,3,62,63,64 instead of MW 8-930A), but ideally I would want to convert the 8-930A request into bins within the program.</p>
  <p>I was thinking about using Excel and some vlookups, but I would prefer to do it directly in python if possible so I don't have to do a bunch of manual work on the file each time I want to run this.</p>
  <p>This is what I have so far:</p>
  <pre><code>from csv import reader    
  
  room_input_file = r&quot;C:\Downloads\rooms.csv&quot;
  course_input_file = r&quot;C:\Downloads\course.csv&quot;
  room_file = reader(open(room_input_file), delimiter='\t')
  course_file = reader(open(course_input_file), delimiter='\t')
  
  
  class Room(object):
      room_instances = [] # list of all Room objects that have been created
      def __init__(self, name, capacity):
          self.times = []
          self.times.extend(range(1,204))
          self.name = name
          self.capacity = capacity
          Room.room_instances.append(self) # adding this to list of Room objects that have been created
  
  
  class Course(object):
      course_instances = [] # list of all Course objects that have been created
      def __init__(self, name, capacity):
          self.name = name
          self.times = []
          self.capacity = capacity
          Course.course_instances.append(self) # adding this to list of Course objects that have been created
          
  for name, cap in room_file:
      x = Room(name,cap)
      
  for name, times, cap in course_file:
      x = Course(name,cap)
      times = times.split(&quot;,&quot;)
      for i in range(0,len(times)):
          times[i] = int(times[i])
      x.times = times
  
  
  for course in Course.course_instances:
      print(course.name)
      print(course.times)
      for room in Room.room_instances:
          if set(course.times).issubset(room.times):
              if room.capacity &gt;= course.capacity:
                  for x in course.times:
                      room.times.remove(x)
                  print(room.name)
                  break
  </code></pre>
  <p>The files are:</p>
  <pre><code>course.csv # unique course identifier, day/time-bins, course-capacity
  00001   1,2,3,62,63,64  71
  00002   1,2,3,62,63,64  41
  00003   1,2,3,62,63,64  31
  
  rooms.csv # room-name, room-capacity
  A110    47
  A210    62
  A220    62
  A230    130
  A250    23
  A320    31
  B100    141
  B170    57
  B270    57
  B300    76
  B370    74
  B470    74
  B570    74
  B500    78
  </code></pre>
  <p>Ideally at this stage the course file would include the below instead (obviously there would be a ton of different times, those were just my proof of concept examples to see if it was correctly assigning rooms, then removing list values):</p>
  <pre><code>00001   MW 8:00am-9:30AM    71
  00002   MW 8:00am-9:30AM    41
  00003   MW 8:00am-9:30AM    31
  </code></pre>
  <p>I'm relatively comfortable with Pandas dataframes and numpy (obviously I'm not an expert based on my code above lol), so if those offer solutions that's fine. Doesn't have to be strictly standard library.</p>
  <p><strong>Also important to note that the end time should not be inclusive: If a course ends at 930A it DOES NOT remove the 930-10A bin.</strong></p>
  <p>Edit: Realized I probably should have included the bins--</p>
  <pre><code>Day Times   bin
  m   8:00am  1
  m   8:30am  2
  m   9:00am  3
  m   9:30am  4
  m   10:00am 5
  m   10:30am 6
  m   11:00am 7
  m   11:30am 8
  m   12:00pm 9
  m   12:30pm 10
  m   1:00pm  11
  m   1:30pm  12
  m   2:00pm  13
  m   2:30pm  14
  m   3:00pm  15
  m   3:30pm  16
  m   4:00pm  17
  m   4:30pm  18
  m   5:00pm  19
  m   5:30pm  20
  m   6:00pm  21
  m   6:30pm  22
  m   7:00pm  23
  m   7:30pm  24
  m   8:00pm  25
  m   8:30pm  26
  m   9:00pm  27
  m   9:30pm  28
  m   10:00pm 29
  t   8:00am  30
  t   8:30am  31
  t   9:00am  32
  t   9:30am  33
  t   10:00am 34
  t   10:30am 35
  t   11:00am 36
  t   11:30am 37
  t   12:00pm 38
  t   12:30pm 39
  t   1:00pm  40
  t   1:30pm  41
  t   2:00pm  42
  t   2:30pm  43
  t   3:00pm  44
  t   3:30pm  45
  t   4:00pm  46
  t   4:30pm  47
  t   5:00pm  48
  t   5:30pm  49
  t   6:00pm  50
  t   6:30pm  51
  t   7:00pm  52
  t   7:30pm  53
  t   8:00pm  54
  t   8:30pm  55
  t   9:00pm  56
  t   9:30pm  57
  t   10:00pm 58
  w   8:00am  59
  w   8:30am  60
  w   9:00am  61
  w   9:30am  62
  w   10:00am 63
  w   10:30am 64
  w   11:00am 65
  w   11:30am 66
  w   12:00pm 67
  w   12:30pm 68
  w   1:00pm  69
  w   1:30pm  70
  w   2:00pm  71
  w   2:30pm  72
  w   3:00pm  73
  w   3:30pm  74
  w   4:00pm  75
  w   4:30pm  76
  w   5:00pm  77
  w   5:30pm  78
  w   6:00pm  79
  w   6:30pm  80
  w   7:00pm  81
  w   7:30pm  82
  w   8:00pm  83
  w   8:30pm  84
  w   9:00pm  85
  w   9:30pm  86
  w   10:00pm 87
  th  8:00am  88
  th  8:30am  89
  th  9:00am  90
  th  9:30am  91
  th  10:00am 92
  th  10:30am 93
  th  11:00am 94
  th  11:30am 95
  th  12:00pm 96
  th  12:30pm 97
  th  1:00pm  98
  th  1:30pm  99
  th  2:00pm  100
  th  2:30pm  101
  th  3:00pm  102
  th  3:30pm  103
  th  4:00pm  104
  th  4:30pm  105
  th  5:00pm  106
  th  5:30pm  107
  th  6:00pm  108
  th  6:30pm  109
  th  7:00pm  110
  th  7:30pm  111
  th  8:00pm  112
  th  8:30pm  113
  th  9:00pm  114
  th  9:30pm  115
  th  10:00pm 116
  f   8:00am  117
  f   8:30am  118
  f   9:00am  119
  f   9:30am  120
  f   10:00am 121
  f   10:30am 122
  f   11:00am 123
  f   11:30am 124
  f   12:00pm 125
  f   12:30pm 126
  f   1:00pm  127
  f   1:30pm  128
  f   2:00pm  129
  f   2:30pm  130
  f   3:00pm  131
  f   3:30pm  132
  f   4:00pm  133
  f   4:30pm  134
  f   5:00pm  135
  f   5:30pm  136
  f   6:00pm  137
  f   6:30pm  138
  f   7:00pm  139
  f   7:30pm  140
  f   8:00pm  141
  f   8:30pm  142
  f   9:00pm  143
  f   9:30pm  144
  f   10:00pm 145
  s   8:00am  146
  s   8:30am  147
  s   9:00am  148
  s   9:30am  149
  s   10:00am 150
  s   10:30am 151
  s   11:00am 152
  s   11:30am 153
  s   12:00pm 154
  s   12:30pm 155
  s   1:00pm  156
  s   1:30pm  157
  s   2:00pm  158
  s   2:30pm  159
  s   3:00pm  160
  s   3:30pm  161
  s   4:00pm  162
  s   4:30pm  163
  s   5:00pm  164
  s   5:30pm  165
  s   6:00pm  166
  s   6:30pm  167
  s   7:00pm  168
  s   7:30pm  169
  s   8:00pm  170
  s   8:30pm  171
  s   9:00pm  172
  s   9:30pm  173
  s   10:00pm 174
  su  8:00am  175
  su  8:30am  176
  su  9:00am  177
  su  9:30am  178
  su  10:00am 179
  su  10:30am 180
  su  11:00am 181
  su  11:30am 182
  su  12:00pm 183
  su  12:30pm 184
  su  1:00pm  185
  su  1:30pm  186
  su  2:00pm  187
  su  2:30pm  188
  su  3:00pm  189
  su  3:30pm  190
  su  4:00pm  191
  su  4:30pm  192
  su  5:00pm  193
  su  5:30pm  194
  su  6:00pm  195
  su  6:30pm  196
  su  7:00pm  197
  su  7:30pm  198
  su  8:00pm  199
  su  8:30pm  200
  su  9:00pm  201
  su  9:30pm  202
  su  10:00pm 203
  </code></pre>
  <p>Edit 2:</p>
  <p>Some samples of default day/time data that I convert to &quot;bins&quot;:</p>
  <pre><code>TTh   11:00AM-12:30PM
  TTh   12:30PM-2:00PM
  MW   4:00PM-5:30PM
  TTh   6:00PM-7:30PM
  MW   12:30PM-2:00PM
  M   12:00PM-2:00PM
  </code></pre>