开发者

PYTHON QUESTION: How to get the number of the repeated elements in a list and arrange data to each element from other list? [closed]

开发者 https://www.devze.com 2022-12-07 22:19 出处:网络
Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this
Closed. This question needs to be more focused. It is not currently accepting answers.

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 question
Let'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 :)

0

精彩评论

暂无评论...
验证码 换一张
取 消