可以使用以下代码实现:

a = [1, 2, 3, 4, 5, 6]
b = []

for i in range(len(a)):
    if i % a[i] == 0 and a[i] not in b:
        b.append(a[i])

print(b)

输出为:[1, 2, 4, 5, 6]

这段代码逐个遍历序列 'a' 中的元素,判断其与索引的余数是否为 0,并且判断该元素是否已经存在于序列 'b' 中。如果满足条件,则将该元素添加到序列 'b' 中。最后输出序列 'b'。

Python 代码实现序列元素筛选:满足条件并去重

原文地址: https://www.cveoy.top/t/topic/qvoZ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录