从列表列表中创建重复值列表

时间:2018-03-12 00:53:15

标签: python-2.7 pandas

我有一个列表名为" indexList"下面。我试图创建一个新列表,其中只包含indexList中出现在indexList中包含的多个列表中的值。有没有一种简单的方法可以做到这一点,还是我需要创建一个哈希或者一个带有计数器的for循环?

print(indexList)

[[14132732, 17507054, 20154219, 57866667, 64995031, 73339549, 76622670, 77054124, 88266242, 95011712, 97504763, 105453976, 119673246, 121145411, 122730527, 136408685, 145004137, 153916914, 160541689, 167759940, 194678471], [14035852, 14239713, 14806084, 28600799, 55796354, 77054124, 80085145, 89842020, 105453976, 105615905, 112819974, 141740256, 141741893, 174759505, 175188439, 189388409, 197055847, 1027845469], [14059532, 55196567, 55855922, 66556068, 89842020, 93011066, 95458113, 105431163, 105615905, 110681306, 160016156, 163230536, 164783106, 175188439, 186797934, 191913967, 331858466, 337685623, 1011598174], [11666669, 12927826, 14049967, 17986728, 30613784, 38761955, 49501165, 52663092, 58344403, 65417742, 75290545, 76769480, 80461647, 81348271, 83741632, 95458113, 95869938, 97144680, 97238886, 108444865, 132547936, 137180880, 144814077, 150365263, 164783106, 166136003, 166380144, 167759940, 189388409, 191913967, 206079517, 239840607, 248336776, 332225104, 1003902828, 1006421644], [14205773, 14239713, 19124994, 27306691, 38457025, 64561619, 76622670, 80290444, 89217656, 100959649, 107140360, 151048919, 167759940, 198478294], [], [15951676, 17986728, 19875521, 30613784, 38761955, 39401305, 39977884, 56603666, 56612203, 58344403, 78354186, 78934707, 89892972, 97320117, 106311786, 126649974, 132547936, 144501061, 147452410, 163699000, 163823179, 167759940, 172118849, 176086128, 232340666, 235833558], [11666669, 14236027, 14806084, 15563629, 15683187, 19124994, 20154219, 24741733, 24788445, 27186241, 27306691, 30613784, 31025020, 38457025, 39280718, 55796354, 55879097, 57136468, 57866667, 62554743, 78354186, 79559892, 79727956, 80689158, 81136486, 83065898, 89842020, 90679924, 92248343, 97144680, 97320117, 105615905, 117722840, 121145411, 121817275, 132547936, 136181420, 136755608, 150697319, 151048919, 151795031, 153916914, 157299696, 163466152, 164783106, 167759940, 192654998, 193361704, 276378790, 277316518, 337517789], [], [24707679, 39555826, 59380375, 76003587, 108444865, 122730527, 162992192, 166380144, 172149940, 175188439, 184932536, 235833558, 235906336, 244838688, 247663297, 277319959, 288845420, 292437922, 311590450, 337094084, 337644502]]

1 个答案:

答案 0 :(得分:1)

我将假设每个子列表中没有重复值。

from collections import Counter
from itertools import chain

counts = Counter(chain(*indexList))
repeats = [key for key,value in counts.items() if value>1]
相关问题