1. Class time!
def greedy(course):length = len(course)course_list=[]course_list.append(course[0])course_end_time = course_list[0][1][1]for i in range(1, length):if course[i][1][0] >= course_end_time:course_list.append(course[i])course_end_time = course[i][1][1]return course_listcourse = {'Biology':(12, 13),'English':(9, 11),'Math':(8, 10),'IT':(10, 12),'Physics':(11,13),}cs = sorted(course.items(), key=lambda item:item[1][1])print('IDK')print('Class', '    Starting time', 'FINISH CLASS!')for i in range(len(cs)):print("{0}{1:7d}:00{2:8d}:00".format(cs[i][0],cs[i][1][0],cs[i][1][1]))s=greedy(cs)print("IDK")print("Class", "   Starting time", "FINISH CLASS!")for i in range(len(s)):print("{0}{1:7d}:00{2:8d}:00".format(s[i][0],s[i][1][0],s[i][1][1]))
def greedy(things):length = len(things)things_list = []things_list.append(things[length-1])weights = things[length-1][1][1]for i in range(length-1, -1, -1):if things[i][1][1] + weights <= max_weight:things_list.append(things[i])weights += things[i][1][1]return things_listthings = {'iWatch':(15000, 0,1),'Asus':(35000, 0,7),'iPhone':(38000, 0,3),'Acer':(40000, 0,8),'Go Pro':(12000, 0,1),}max_weight = 1th = sorted(things.items(), key=lambda item:item[1][0])print("IDK")print('Product', '                Price', 'Weight')for i in range(len(th)):print("{0:8s}{1:10d}{2:10.2f}".format(th[i][0],th[i][1][0],th[i][1][1]))t = greedy(th)print("IDK")print("Product", "                            Price", "Weight")for i in range(len(t)):print("{0:8s}{1:10d}{2:10.2f}".format(t[i][0],t[i][1][0],t[i][1][1]))

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

SUBSTR() Character Function — Oracle SQL Example

Local To-Dos for Developers

Role of Documentation and Software Architecture in Cubix

Easy mysqldump backups by example.

Adding reflections to your scenes in Unity

Graceful shutdown in go

Scoping Activities Subcomponents with dagger-android

Ten features you can build for your server-side testing tool

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Che Kai LIANG

Che Kai LIANG

More from Medium

Q#63 Calculating a moving average — using python

Single underscore and Double underscore in Python.

Find The Needles: Python Version

Introduction to Python Programming Part 3— Containers