Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Skillenza Common subjects
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
#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'] 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]) for item in sorted_x[1:]: temp = [] for s in perma: #print(sub.get(item[0])[0]) if(sub.get(s)[0] <= sub.get(item[0])[1] or sub.get(s)[1] >= sub.get(item[0])[0]): #print('HI') #temp = temp.append(item[0]) perma.extend(temp) print(perma)
[
+
]
Show input
edit mode
|
history
|
discussion