我需要加快計算此代碼中不同元素的時間,並且我不確定如何執行更快的計數。數組中元素的快速截然不同的列表python
def process_columns(columns):
with open(columns, 'r') as src:
data = csv.reader(src, delimiter ='\t', skipinitialspace = False)
category = []
group = columns.split("/")
group = group[-1].split(".")
if group[0] in ["data_1", "data_2"]:
for row in data:
if row[0] not in category:
category.append(row[0])
message = "\t%d distinct elements from %ss" % (len(category), group[0])
print message
@折速爲什麼附加到列表後轉換爲設置? –
@ Jean-FrançoisFabre不需要,不需要。實際上提到它只是作爲OP現有代碼的快速修復。但有更好的方法... –
@速速我們正在等待你的一個很好的答案,因爲你知道如何做飯:) –