Duplicate Character Counter in Python

Published on 14 May 2022 (Updated: 14 May 2022)

Welcome to the Duplicate Character Counter in Python page! Here, you'll find the source code for this program as well as a description of how the program works.

Current Solution

import sys

if len(sys.argv) != 2 or not sys.argv[1]:
    print("Usage: please provide a string")
    sys.exit()

counter = dict()
dupes = False
for char in sys.argv[1]:
    counter.setdefault(char, 0)
    counter[char] += 1
    if counter[char] > 1:
        dupes = True

if dupes:
    for key, value in counter.items():
        if value > 1:
            print(f"{key}: {value}")
else:
    print("No duplicate characters")

Duplicate Character Counter in Python was written by:

If you see anything you'd like to change or update, please consider contributing.

How to Implement the Solution

No 'How to Implement the Solution' section available. Please consider contributing.

How to Run the Solution

No 'How to Run the Solution' section available. Please consider contributing.