Skip to content

Commit cf20a7f

Browse files
committed
refine print
1 parent 1bbdf37 commit cf20a7f

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed
Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
# example2.py
22
#
33
# Remove duplicate entries from a sequence while keeping order
4+
from typing import Set
45

5-
def dedupe(items, key=None):
6+
7+
def dedupe(items, key=None) -> Set:
68
seen = set()
79
for item in items:
810
val = item if key is None else key(item)
911
if val not in seen:
1012
yield item
1113
seen.add(val)
1214

15+
1316
if __name__ == '__main__':
14-
a = [
17+
a = [
1518
{'x': 2, 'y': 3},
1619
{'x': 1, 'y': 4},
1720
{'x': 2, 'y': 3},
1821
{'x': 2, 'y': 3},
1922
{'x': 10, 'y': 15}
20-
]
21-
print(a)
22-
print(list(dedupe(a, key=lambda a: (a['x'],a['y']))))
23-
23+
]
24+
print("original list", a)
25+
de_duplicate = dedupe(a, key=lambda a: (a['x'], a['y']))
26+
print("deduplicate(generator): ", de_duplicate)
27+
print("remove duplicate", list(dedupe(a, key=lambda a: (a['x'], a['y']))))

0 commit comments

Comments
 (0)