0

I need a way to generate a list of all five minute increments between some arbitrary set of hours. So, for example, if I wanted 3p and 4p, it would look like:

3:00 PM, 3:10 PM, 3:15 PM, 3:20 PM, etc....

Any thoughts on the quickest way to do this?

otictac1
  • 155
  • 1
  • 11

1 Answers1

0

QuicknDirty

for i in range (60):
   if i % 5 == 0:
      print('X:{}PM'.format (i))

Or as function ;)

def getMinutes (hour, minuteSteps):
    steps = []
    for i in range (60):
       if i % minuteSteps == 0:
           steps.append('{}:{}PM'.format (hour,i))
    return steps
Ben
  • 673
  • 3
  • 11
  • Consider using the format string of `'{}:{:02d} PM'` to zero pad those times where the minute is less than 10. – Noah Nov 22 '15 at 02:39
  • How would this handle crossing over from 11a-12p? – otictac1 Nov 22 '15 at 02:43
  • You can eliminate the if statement if you use `for i in range(0, 60, minuteSteps)` – Noah Nov 22 '15 at 02:44
  • Also, I really want it to be flexible so in case I needed 5 hours (say from 11a-4p), it could do that. – otictac1 Nov 22 '15 at 02:45
  • You could archive this with wrapping another for loop around it like for hour in range (11, 16): hour = hour % 12. The modulo 12 gives you your am/pm stuff. – Ben Nov 22 '15 at 10:29