

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Generate two output strings depending upon occurrence of character in input string in Python
In this program , we take a string and count the characters in it with certain condition. The first condition is to capture all those characters which occur only once and the second condition is to capture all the characters which occur more than once. Then we list them out.
Below is the logical steps we are going to follow to get this result.
- Counter converts the strings into Dictionary which is having keys and value.
- Then separate list of characters occurring once and occurring more than once using the join()
In the below program we take the input string and
Example
from collections import Counter def Inputstrings(load): Dict = Counter(load) occurrence = [key for (key, value) in Dict.items() if value == 1] occurrence_1 = [key for (key, value) in Dict.items() if value > 1] occurrence.sort() occurrence_1.sort() print('characters occurring once:') print(''.join(occurrence)) print('characters occurring more than once:') print(''.join(occurrence_1)) if __name__ == "__main__": load = "Tutorialspoint has best tutorials" Inputstrings(load)
Running the above code gives us the following result −
Output
characters occurring once: Tbehnp characters occurring more than once: ailorstu
- Related Questions & Answers
- Java program to check occurrence of each character in String
- Python program to find occurrence to each character in given string
- C Program to find maximum occurrence of character in a string
- C Program to find minimum occurrence of character in a string
- String function to replace nth occurrence of a character in a string JavaScript
- Finding the last occurrence of a character in a String in Java
- C program to replace all occurrence of a character in a string
- C# Program to find number of occurrence of a character in a String
- Python - Replace duplicate Occurrence in String
- Python – Split Strings on Prefix Occurrence
- What are the input and output for strings in C language?
- Replace first occurrence of a character in Java
- How to generate JSON output using Python?
- Largest Merge of Two Strings in Python
- Java program to count the occurrence of each character in a string using Hashmap
Advertisements