comparison list of lists python

时间:2016-08-31 17:17:27

标签: list python-2.7 comparison

how i can do this

Asana is exploring a smart-workload feature designed to streamline task assignment between coworkers. Newly created tasks will be automatically assigned to the team member with the lightest workload. For each person the following information is known:

name - their name, a string containing only uppercase and lowercase letters;
status - their vacation indicator status, which is "0" if the person is on a vacation, or "1" otherwise;
projects - the number of projects they are currently involved in;
tasks - the number of tasks assigned to the report.

If a person's vacation indicator value is set to "0", this means they are on vacation and cannot be assigned new tasks. Conversely, a vacation indicator value of "1" means they are open to receive task assignments.

Asana sorts team members according to their availability. Person A has a higher availability than person B if they have fewer tasks to do than B, or if these numbers are equal but A has fewer assigned projects than B. Put another way, we can say that person A has a higher availability than person B if their (tasks, projects) pair is less than the same pair for B.

Your task is to find the name of the person with the highest availability. It is guaranteed that there is exactly one such person.

Example

Consider information about two team members:
    John, with status = "1", projects = "2" and tasks = "6", represented as ["John", "1", "2", "6"];
    Martin, with status = "1", projects = "1" and tasks = "5", represented as ["Martin", "1", "1", "5"].

For this case, the output should be smartAssigning(information) = "Martin".

Here John and Martin's vacation indicators are both "1", so both of them are open to new assignments. Martin is only assigned 5 tasks while John is assigned 6, so Martin has the highest availability.

For the following employees' information:
    John, with status = "1", projects = "2" and tasks = "6", represented as ["John", "1", "2", "6"];
    Martin, with status = "0", projects = "1" and tasks = "5", represented as ["Martin", "0", "1", "5"];

the output should be smartAssigning(information) = "John".

In this example Martin cannot be assigned any new tasks because his vacation indicator is "0". Therefore, "John" has the highest availability.

For the following information:
    John, with status = "1", projects = "1" and tasks = "6", represented as ["John", "1", "1", "6"];
    Martin, with status = "1", projects = "2" and tasks = "6", represented as ["Martin", "1", "2", "6"];

the output should be smartAssigning(information) = "John".

Both John and Martin's vacation indicators are "1", and the number of tasks each of them is assigned is 6. However, John is involved in just 1 project, while Martin is involved in 2, so John has the highest availability.

i do this show image

1 个答案:

答案 0 :(得分:0)

满足您想要的计划要求

  1. 确保此人未休假(状态= 1)。
  2. 选择任务量最少的人。
  3. 如果两个人的任务数相同,则选择项目数量最少的人。
  4. 基本上,你需要一个for循环来遍历人员列表,并对每个人的任务数量和项目数量进行比较。

    您还需要一个占位符来抓住具有最高可用性的人。可用性定义为“首先分配任务量最少的人,然后在任务编号相同时分配最少量的项目”

    #input is 2D array information[i][j]
    #pseudo enumeration for j # information[i][j] for logic
    name = 0
    status = 1
    projects = 2
    tasks = 3
    
    #currently assigned index number i # information[i][j]
    currently_assigned = 0
    
    #loop through to find first available worker
    for n in information:
        if n[status] == 1:
            currently_assigned = n
            break
    
    for i in information:
        if i[status] == 1:
            # Task checking
            if (i[tasks] < information[currently_assigned][tasks]):
                currently_assigned = i
            # Project checking if they have the same number of tasks
            elif (i[tasks] == information[currently_assigned][tasks]):
                if (i[projects] < information[currently_assigned][projects]):
                    currently_assigned = i
    
    return information[currently_assigned][name]