在具有多个条件的多个列表上应用 if 语句

Apply if statement on multiple lists with multiple conditions

我想将 ID 附加到满足特定条件的列表中。

    output = []
    areac = [4, 4, 4, 4, 1, 6, 7,8,9,6, 10, 11]
    arean = [1, 1, 1, 4, 5, 6, 7,8,9,10, 10, 10]
    id = [1, 2, 3, 4, 5, 6, 7,8,9,10, 11, 12]
    dist = [2, 2, 2, 4, 5, 6, 7.2,5,5,5, 8.5, 9.1]
    for a,b,c,d in zip(areac,arean,id,dist):
            if a >= 5 and b==b and d >= 3:
                output.append(c)
                print(comp)
            else:
                pass
The condition is the following:
- areacount has to be >= 5
- At least 3 ids with a distance of >= 3 with the same area_number

所以 id 输出应该是 [10,11,12]。我已经用 Counter 尝试了不同的尝试,但没有成功。感谢您的帮助!

给你:

我将列表名称更改为更具描述性的名称。

output = []
area_counts = [4, 4, 4, 4, 1, 6, 7, 8, 9, 6, 10, 11]
area_numbers = [1, 1, 1, 4, 5, 6, 7, 8, 9, 10, 10, 10]
ids = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
distances = [2, 2, 2, 4, 5, 6, 7.2, 5, 5, 5, 8.5, 9.1]

temp_numbers, temp_ids = [], []
for count, number, id, distance in zip(counts, numbers, ids, distances):
    if count >= 5 and distance >= 3:
        temp_numbers.append(number)
        temp_ids.append(id)

for (number, id) in zip(temp_numbers, temp_ids):
    if temp_numbers.count(number) == 3:
        output.append(id)

output 将是:

[10, 11, 12]