data = {'06': ['11', '26', '41', '56'], '12': ['06', '36'], '11': ['06', '36'], '07': ['11', '26', '41', '56'], '16': ['11', '26', '41', '56'], '14': ['06', '36'], '17': ['11', '26', '41', '56'], '20': ['05', '35'], '15': ['06', '36', '56'], '09': ['06', '36'], '21': ['05', '35'], '22': ['05', '35'], '23': ['05', '35'], '19': ['11', '40'], '08': ['11', '26', '41'], '13': ['06', '36'], '10': ['06', '36'], '18': ['11', '26', '41', '56']} # It's much simpler if we convert the schedule to a more easily processable form: # Flat list of all the times, represented by a single int (hour*60+minute) data2 = [int(h) * 60 + int(m) for h in data.keys() for m in data[h]] def find_times_in_the_next_half_hour(time): start_hour, start_minute = map(int, time.split('.')) start = start_hour * 60 + start_minute end = start + 30 after = list(filter(lambda x: start <= x <= end, data2)) return list(map(lambda x: '%02d.%02d' % (x // 60, x % 60), after)) print(find_times_in_the_next_half_hour('07.35'))
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question