day_data = { "0700": "-", "0745": "-", "0830": "-", "0915": "-", "1000": "B", "1045": "M", "1130": "-", "1215": "-", "1300": "-", "1345": "B", "1430": "-", "1515": "M", "1600": "B", "1645": "-", "1730": "M", "1815": "B", "1900": "-", "1945": "-", "2030": "-", "2115": "-", "2200": "-" } FM_data = filter(lambda x: day_data[x] == 'M', day_data) print "These are today's FM times:",FM_data print print "This is a list of today's lessons:" # list to hold the day data output_text = [] # append data to the list for lesson in day_data: if day_data[lesson] == "": text = "empty" else: text = day_data[lesson] output_text.append(lesson + " " + text) # sort the list output_text.sort() # print the sorted data for lesson in output_text: print lesson
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