Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Skillenza- Subjects
#python 3.5.2 from collections import defaultdict as dd import operator subjects = ['Maths 16:00 18:00','ComputerScience 12:00 13:00','Physics 12:30 14:00','Chemistry 14:00 16:30', 'Science 16:30 18:00'] temp = (subjects[0].split())[1].replace(':','') #print(int(temp)) conflict = dd(int) sub = dd(list) for each in subjects: temp = each.split() sub[temp[0]] .append(int(temp[1].replace(':',''))) sub[temp[0]] .append(int(temp[2].replace(':',''))) #sub[temp[0]] += temp[2] #print(int(temp[1].replace(':',''))) conflict[temp[0]]+= 0 #print(sub) for item in sub.items(): for s in sub.items(): if(item[0] != s[0] and (item[1][0]<=s[1][0]<item[1][1] or item[1][0]<s[1][1]<=item[1][1])): conflict[item[0]] += 1 #print(item) #print(s) #print(s[1][0]) #print('====') sorted_x = sorted(conflict.items(), key=operator.itemgetter(1)) #print(sorted_x) #print(conflict) perma = [] perma.append(sorted_x[0][0]) print(sorted_x) for item in sorted_x[1:]: temp = [] flag = True for s in perma: #print("Iteme",item) #print("Subject",s) if(sub.get(s)[1] <= sub.get(item[0])[0] or sub.get(s)[0] >= sub.get(item[0])[1]): ##print(" Start item: ",sub.get(item[0])[1]) #print(" Start sub: ",sub.get(s)[1]) #print(" Start item: ",sub.get(item[0])[0]) #temp = pass #temp.append(item[0]) else: #print('Here', flag); flag = False #print(temp) if(flag): #print("added") perma.append(item[0]) #print("final after: ",perma) print(perma)
run
|
edit
|
history
|
help
0
fb_series
emoji 2
InsertionSort
python codewars
Z Pattern ( first python program)
permutations example
(P3) Rok przestępny
HW5, SelectionSort FINNAL
Hi.py
Random number