Advertisement
Guest User

bath schedule

a guest
Mar 27th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.90 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import datetime
  3. from random import shuffle
  4. from collections import OrderedDict
  5.  
  6. def date_range(start_date, end_date):
  7.     """
  8.    returns a datetime object for a range of dates
  9.    """
  10.     if start_date <= end_date:
  11.         for dt in range( ( end_date - start_date ).days + 1 ):
  12.             yield start_date + datetime.timedelta( dt )
  13.     else:
  14.         for dt in range( ( start_date - end_date ).days + 1 ):
  15.             yield start_date - datetime.timedelta( dt )
  16.  
  17.  
  18. def date_dict(start_date, end_date):
  19.     """
  20.    creates a dictionary where the keys are
  21.    dates from the supplied range with the
  22.    order preserved
  23.    """
  24.     dt_dict = OrderedDict()
  25.     for date in date_range(start_date, end_date):
  26.         dt_dict[str(date)] = ''
  27.     return dt_dict
  28.  
  29. def random_list2dict_apply(my_dict, my_list):
  30.     """
  31.    takes a list and shuffles it, then puts it
  32.    in to the key values of the supplied dictionary
  33.    when a list item is applied, it is then popped,
  34.    when the list runs out, it is refreshed and the
  35.    process starts over again until the end of the
  36.    dictionary
  37.    """
  38.     shfl_lst = list(my_list)
  39.     shuffle(shfl_lst)
  40.  
  41.     for key in my_dict:
  42.         if len(shfl_lst) != 0:
  43.             my_dict[key] = shfl_lst[0]
  44.             shfl_lst.pop(0)
  45.         else:
  46.             shfl_lst = list(my_list)
  47.             shuffle(shfl_lst)
  48.             my_dict[key] = shfl_lst[0]
  49.             shfl_lst.pop(0)
  50.  
  51.     return my_dict
  52.  
  53. def main():
  54.  
  55.     start_date = datetime.date( year = 2017, month = 2, day = 1 )
  56.     end_date = datetime.date( year = 2017, month = 3, day = 1 )
  57.     arbitrary_list = ['Davidson', 'Gabrielle', 'Shane']
  58.  
  59.     dt_range_dict = date_dict(start_date, end_date)
  60.  
  61.     randomized_value_dict = random_list2dict_apply(dt_range_dict, arbitrary_list)
  62.     for key, value in randomized_value_dict.items():
  63.          print (key, value)
  64. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement