May-13-2019, 10:51 PM
I have a idea for the code in the original post.
You repeat yourself. With some tricks,
you write code once and then you enter the data.
You repeat yourself. With some tricks,
you write code once and then you enter the data.
DAYTIMES = { 'midnight': (23, 1), 'day': (6, 20), } def overlapping_in_range(value, min_val, max_val): if min_val < max_val: return min_val <= value < max_val elif min_val > max_val: return value >= min_val or value < max_val def get_daytime(hour): for daytime, (mmin, mmax) in DAYTIMES.items(): if overlapping_in_range(hour, mmin, mmax): return daytime return ''
[(x, get_daytime(x)) for x in range(25)]
Output:[(0, 'midnight'),
(1, ''),
(2, ''),
(3, ''),
(4, ''),
(5, ''),
(6, 'day'),
(7, 'day'),
(8, 'day'),
(9, 'day'),
(10, 'day'),
(11, 'day'),
(12, 'day'),
(13, 'day'),
(14, 'day'),
(15, 'day'),
(16, 'day'),
(17, 'day'),
(18, 'day'),
(19, 'day'),
(20, ''),
(21, ''),
(22, ''),
(23, 'midnight'),
(24, 'midnight')]
Have to sleep now.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!