Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 hours ago.
Improve this questionLet's assume I have number of employees with code numbers (1000, 2000, 3000).
and I have a list with their working hours. The employees are repeated in the list!
I want to find to number of employees to arrange the number of hours for every employee in a separate list. Considering that I need to find first the number of of the employees defined in the list
and how often everyone is repeated in the list.
list_employees_code = [1000, 2000, 3000, 1000, 2000, 3000,1000, 2000, 3000]
How to find that the number of the employees in the "list_emplyee_code" is 3 (1000, 2000, 3000)?
How to calculate how many times each employee number is repeated in the list "list_3_employees_code" .
At the end I will be able to create a statistic about the number of hours for each employee over
a specific period of time,
list_3_employee_number_hours = [ 45, 35, 70, 150, 300, 100, 111, 217, 319] How to extract a list (in this case the number of working hours) for every employee?
I was expecting to have the output below:
number employees = 3
List_employees = [1000, 2000, 3000]
expected outputs: employee_1000_hrs = [45, 开发者_开发知识库150, 111]
employee_2000_hrs = [35, 300, 217]
employee_3000_hrs = [70, 100, 319]
For the first question, there is a way:
list_employees=[]
[list_employees.append(employee_code) for employee_code in list_employees_code if employee_code not in list_employees]
print('number employees = %s\nList_employees = %s'%(len(list_employees),list_employees))
I can't clearly understand the second one. Does the second question work under the first condition? If so, is the length of employee_xxxx_hrs
fixed? Or it will change with the changement of the numbers for employees?
PS: It's my first time to answer other's question, so if there are some disadvantages pls forgive me :)
精彩评论