-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathassociated-query.py
More file actions
26 lines (25 loc) · 842 Bytes
/
associated-query.py
File metadata and controls
26 lines (25 loc) · 842 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class Solution:
"""
@param datalist1: a list represents the employee table
@param datalist2: a list represents the employee hours table
@return: Returns a list of strings represents the datalist3
"""
def getList(self, datalist1, datalist2):
# write your code here
ret = []
di = {}
for data in datalist2:
di[data[0]] = [data[2], data[4], data[6]]
for data in datalist1:
uid = data[0]
uname = data[1]
if uid in di:
line = [uname]
line.extend(di[uid])
total = 0
for i in di[uid]:
total += int(i)
line.append(str(total))
ret.append(line)
return ret;
# easy: https://www.lintcode.com/problem/associated-query/