Write a program to print the duplicate characters in the given stringInput FormatGiven a stringOutput Formatprint the duplicate characters separated by space ':'Constraint :1 <= string length <= 100Note: If more than one occurred then print the first occurrencethe string might have upper case letter that should be considered as lowercase
Question
Write a program to print the duplicate characters in the given stringInput FormatGiven a stringOutput Formatprint the duplicate characters separated by space ':'Constraint :1 <= string length <= 100Note: If more than one occurred then print the first occurrencethe string might have upper case letter that should be considered as lowercase
Solution
Here is a Python program that prints the duplicate characters in a given string. It converts all uppercase letters to lowercase to ensure case insensitivity.
def print_duplicates(s):
s = s.lower()
duplicates = []
for char in s:
if s.count(char) > 1 and char not in duplicates:
duplicates.append(char)
print(":".join(duplicates))
# Test the function
print_duplicates("Hello World")
In this program, we first convert the string to lowercase. Then we iterate over each character in the string. If the count of that character in the string is more than 1 and it is not already in our list of duplicates, we add it to the list. Finally, we print the list of duplicates, joining them with a colon.
This program will print the first occurrence of each duplicate character. If a character appears more than once, it will still only be printed once.
Similar Questions
Problem StatementWrite a program to remove the duplicate characters in the given stringInput FormatGiven a stringOutput Formatremove the duplicate characters and print the unique string
Debug the given python program to print the unique letters (which are not common in both the strings), irrespective of case. Print output in upper case. Avoid repetition of l
Given a string without duplicates, print all the permutations of the string in a lexicographically order.Input FormatFirst line of input contains T - number of test cases. Its followed by T lines, each contains a single string consisting only of lowercase Enghish alphabets.ConstraintsFor each test case, print the test case number as shown, followed by all the permutations of the string in a lexicographically order, separated by newline.Output Format1 <= T <= 1001 <= len(str) <= 8Sample Input 02algodsSample Output 0Test Case #1:agloagolalgoalogaoglaolggalogaolglaogloagoalgolalagolaoglgaolgoaloaglogaoagloalgogaloglaolagolgaTest Case #2:dssd
Given a string of characters, find the first repeating character.Input FormatThe first line of input contains T - the number of test cases. It's followed by T lines, each line contains a single string of characters.Output FormatFor each test case, print the first repeating character, separated by a new line. If there are none, print '.'.Constraints1 <= T <= 1000'a' <= str[i] <= 'z'1 <= len(str) <= 104ExampleInput4datastructuresalgorithmssmartinterviewshackerrankOutputa.sa
Check whether the given character is in upper case or lower case or noneInput Format:Enter a Character as inputOutput Format:Print the output as "UPPERCASE" or "LOWERCASE" or "NONE"Constraints:0 <= INPUT <= 2^7Sample Input 1:ZSample Output 1:UPPERCASESample Input 2:zSample Output 2:LOWERCASE
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.