1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
| import datetime as dt
import re
import math
def solution(m, musicinfos):
answer = list()
lower_repl = lambda match: match.group(1)[0].lower()
sharp_repl = lambda s: re.sub('([A-G]#)', lower_repl, s)
m = sharp_repl(m)
strptime = lambda x: dt.timedelta(hours=int(x[0]),minutes=int(x[1]))
for info in musicinfos:
start, end, title, chord = info.split(',')
plays = (strptime(end.split(':'))-strptime(start.split(':'))).seconds//60
chord = sharp_repl(chord)
chord = (chord * math.ceil(plays/len(chord)))[:plays]
if m in chord:
answer.append((plays,title))
return sorted(answer, key=lambda x: x[0], reverse=True)[0][1] if len(answer) else '(None)'
|