-
Notifications
You must be signed in to change notification settings - Fork 1
/
mapping.py
63 lines (50 loc) · 1.56 KB
/
mapping.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python
# coding=utf-8
import pprint
import csv
class MyPrettyPrinter(pprint.PrettyPrinter):
def format(self, object, context, maxlevels, level):
if isinstance(object, unicode):
return (object.encode('utf8'), True, False)
return pprint.PrettyPrinter.format(self, object, context, maxlevels, level)
# pp = MyPrettyPrinter()
pp = pprint
is_unique = True
gta_keys = []
gta_keys_sorted = []
gta_keys_dup = set()
duplicates = {}
with open('Confident.csv', encoding='utf-8-sig') as csvfile:
reader = csv.DictReader(csvfile, delimiter='|')
# pp.pprint(reader.__class__)
# pp.pprint(reader.fieldnames)
# pp.pprint(reader.line_num)reader.
for row in reader:
if row['GTAKey']:
# pp.pprint(row['GTAKey'])
gta_keys.append(row['GTAKey'])
# pp.pprint(reader.line_num)
csvfile.seek(0)
gta_keys_sorted = sorted(gta_keys)
pre_key = ''
for key in gta_keys_sorted:
if pre_key == key:
gta_keys_dup.add(key)
pre_key = key
pp.pprint('GTA keys dup list: ' + str(gta_keys_dup))
for row in reader:
a = 1
if row['GTAKey'] in gta_keys_dup:
if row['GTAKey'] in duplicates:
duplicates[row['GTAKey']].append(row)
else:
duplicates[row['GTAKey']] = [row]
# indices = [i for i, x in enumerate(gta_keys) if x == row['GTAKey']]
# if len(indices) >= 2:
# if row['GTAKey'] in duplicates:
# duplicates[row['GTAKey']].append(row)
# else:
# duplicates[row['GTAKey']] = [row]
pp.pprint('/// /// /// Test Result /// /// ///')
pp.pprint(duplicates)
# pp.pprint(gta_keys)