我有一个如下所示的列表:
l=[(['amandviw'], ['09.01'], [11, 0, 0, 0, 0]), (['amandviw'], ['09.03'], [6, 0, 5, 0, 0]), (['amandviw'], ['10.01'], [10, 0, 0, 0, 1]), (['amandviw'], ['10.02'], [10, 0, 0, 0, 1]), (['amandviw'], ['10.03'], [10, 0, 1, 0, 0]), (['amandviw'], ['10.05'], [16, 4, 2, 0, 1]), (['amandviw'], ['10.06'], [23, 0, 0, 0, 0]), (['amandviw'], ['10.07'], [8, 0, 0, 0, 3]), (['archerj'], ['09.01'], [0, 0, 0, 0, 0]), (['archerj'], ['09.03'], [0, 0, 0, 0, 0]), (['archerj'], ['10.01'], [0, 0, 0, 0, 0]), (['archerj'], ['10.02'], [0, 0, 0, 0, 0]), (['archerj'], ['10.03'], [0, 0, 0, 0, 0]), (['archerj'], ['10.05'], [0, 1, 0, 0, 0]), (['archerj'], ['10.06'], [1, 0, 0, 0, 0]), (['archerj'], ['10.07'], [0, 0, 0, 0, 0]), (['dwickett'], ['09.01'], [9, 0, 2, 0, 1]), (['dwickett'], ['09.03'], [5, 1, 0, 0, 6]), (['dwickett'], ['10.01'], [12, 0, 0, 0, 0]), (['dwickett'], ['10.02'], [10, 0, 2, 0, 0]), (['dwickett'], ['10.03'], [11, 0, 0, 0, 1]), (['dwickett'], ['10.05'], [13, 4, 2, 0, 6]), (['dwickett'], ['10.06'], [21, 1, 0, 0, 3]), (['dwickett'], ['10.07'], [8, 0, 3, 0, 1]), (['gandhi7'], ['09.01'], [27, 0, 0, 0, 1]), (['gandhi7'], ['09.03'], [28, 0, 0, 0, 0]), (['gandhi7'], ['10.01'], [27, 0, 0, 0, 1]), (['gandhi7'], ['10.02'], [27, 0, 0, 0, 1]), (['gandhi7'], ['10.03'], [26, 0, 1, 0, 1]), (['gandhi7'], ['10.05'], [37, 9, 3, 0, 8]), (['gandhi7'], ['10.06'], [55, 1, 0, 0, 1]), (['gandhi7'], ['10.07'], [15, 0, 10, 0, 3]), (['lammp'], ['09.01'], [12, 0, 0, 0, 3]), (['lammp'], ['09.03'], [13, 0, 0, 0, 2]), (['lammp'], ['10.01'], [12, 0, 0, 0, 3]), (['lammp'], ['10.02'], [12, 0, 0, 0, 3]), (['lammp'], ['10.03'], [12, 0, 0, 0, 3]), (['lammp'], ['10.05'], [17, 3, 2, 0, 9]), (['lammp'], ['10.06'], [26, 0, 1, 0, 4]), (['lammp'], ['10.07'], [5, 0, 4, 0, 6]), (['lee1131'], ['09.01'], [9, 0, 0, 0, 1]), (['lee1131'], ['09.03'], [7, 0, 1, 0, 2]), (['lee1131'], ['10.01'], [9, 0, 0, 0, 1]), (['lee1131'], ['10.02'], [9, 0, 0, 0, 1]), (['lee1131'], ['10.03'], [8, 0, 1, 0, 1]), (['lee1131'], ['10.05'], [16, 1, 2, 0, 2]), (['lee1131'], ['10.06'], [20, 0, 0, 0, 1]), (['lee1131'], ['10.07'], [7, 0, 2, 0, 1]), (['pzibley'], ['09.01'], [7, 2, 0, 0, 1]), (['pzibley'], ['09.03'], [8, 0, 2, 0, 0]), (['pzibley'], ['10.01'], [8, 1, 0, 0, 1]), (['pzibley'], ['10.02'], [9, 0, 0, 0, 1]), (['pzibley'], ['10.03'], [9, 0, 0, 0, 1]), (['pzibley'], ['10.05'], [13, 1, 3, 0, 4]), (['pzibley'], ['10.06'], [16, 0, 1, 0, 4]), (['pzibley'], ['10.07'], [4, 0, 4, 0, 2]), (['qiu58'], ['09.01'], [35, 0, 0, 0, 1]), (['qiu58'], ['09.03'], [35, 0, 0, 0, 1]), (['qiu58'], ['10.01'], [35, 0, 0, 0, 1]), (['qiu58'], ['10.02'], [35, 0, 0, 0, 1]), (['qiu58'], ['10.03'], [27, 0, 7, 0, 2]), (['qiu58'], ['10.05'], [40, 20, 4, 0, 9]), (['qiu58'], ['10.06'], [58, 13, 0, 0, 2]), (['qiu58'], ['10.07'], [23, 0, 11, 0, 2]), (['yeggy'], ['09.01'], [11, 0, 0, 0, 0]), (['yeggy'], ['09.03'], [10, 0, 0, 0, 2]), (['yeggy'], ['10.01'], [11, 0, 0, 0, 0]), (['yeggy'], ['10.02'], [11, 0, 0, 0, 0]), (['yeggy'], ['10.03'], [10, 1, 0, 0, 0]), (['yeggy'], ['10.05'], [17, 3, 3, 0, 2]), (['yeggy'], ['10.06'], [21, 0, 2, 0, 2]), (['yeggy'], ['10.07'], [6, 0, 5, 0, 1])]
我想检索每个项目的第一个元素的唯一值,所以我正在寻找这样的东西:
l_unique=('dwickett', 'amandviw', 'yeggy', 'pzibley', 'lammp', 'gandhi7', 'archerj')
答案 0 :(得分:1)
您可以使用集合理解:
l = [ (['dwickett'], ['09.01'], [9, 0, 2, 0, 1]),
(['dwickett'], ['09.03'], [5, 1, 0, 0, 6]),
(['amandviw'], ['09.03'], [6, 0, 5, 0, 0]),
(['amandviw'], ['09.03'], [6, 0, 5, 0, 0]) ]
s = {item[0][0] for item in l}
结果:
>>> s
{'dwickett', 'amandviw'}