Misc-Download-Scripts/charlierose.com/sort_remove_duplicates.py
2018-04-23 12:44:08 -04:00

23 lines
485 B
Python

import csv
import os
rows = []
with open("links.csv", 'rb') as f:
reader = csv.reader(f)
for row in reader:
if row not in rows:
rows.append(row)
def get_key(item):
return int(os.path.split(item[0])[1])
sorted_list = sorted(rows, key=get_key)
with open('links_sorted.csv', 'a') as csv_file:
csv_writer = csv.writer(csv_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
for row in sorted_list:
csv_writer.writerow(row)