Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys;
- abs_path = sys.stdin.readline().rstrip('\n')
- params = sys.stdin.readline().split(',')
- if len(params) != 3:
- print "Invalid Input"
- sys.exit();
- dept = params[0]
- page_size = int(params[1])
- page_num = int(params[2]) - 1
- def FileParser(path):
- f = open(path)
- row = f.readline()
- data_dict = {}
- while row != '':
- row = f.readline()
- if row != '':
- row = row.rstrip('\n')
- columns = row.split(',')
- temp_dict = {}
- dept_id = columns[0]
- temp_dict['dept'] = dept_id
- temp_dict['id'] = columns[1]
- name_parts = columns[2].split(" ")
- if len(name_parts) > 1:
- temp_dict['fname'] = name_parts[1]
- else:
- temp_dict['fname'] = columns[2]
- temp_dict['full_name'] = columns[2]
- if not dept_id in data_dict:
- data_dict[dept_id] = []
- data_dict[dept_id].append(temp_dict)
- f.close()
- for department_id in data_dict:
- data_dict[department_id].sort(key=lambda k: len(k['full_name']))
- return data_dict;
- emp_dict = FileParser(abs_path)
- if dept in emp_dict:
- offset = page_num * page_size
- if offset > 0:
- offset -= 1
- dept_size = len(emp_dict[dept])
- if offset < dept_size:
- arr = []
- for x in range(offset,min(dept_size,offset+page_size)):
- arr.append(emp_dict[dept][x])
- arr.sort()
- for emp in arr:
- print ','.join([str(dept),emp['id'],emp['full_name']])
- sys.exit()
- print "Data Unavailable"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement