From 03511ff1f97785a944c43d68f88de1f0ddfef0d7 Mon Sep 17 00:00:00 2001 From: vaishnavprachi98 Date: Thu, 31 Oct 2019 18:42:59 +0530 Subject: [PATCH] Added a program to check number of duplicates and remove them --- check_and_remove_duplicates.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 check_and_remove_duplicates.py diff --git a/check_and_remove_duplicates.py b/check_and_remove_duplicates.py new file mode 100644 index 0000000..991ca0f --- /dev/null +++ b/check_and_remove_duplicates.py @@ -0,0 +1,11 @@ +import collections +a = [1,1,1,1,2,2,2,2,3,3,4,5,5] +counter=collections.Counter(a) +print(counter) +# Counter({1: 4, 2: 4, 3: 2, 5: 2, 4: 1}) +print(counter.values()) +# [4, 4, 2, 1, 2] +print(counter.keys()) +# [1, 2, 3, 4, 5] +print(counter.most_common(3)) +# [(1, 4), (2, 4), (3, 2)] \ No newline at end of file