forked from ossamamehmood/Hacktoberfest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
string_generate.py
30 lines (23 loc) · 867 Bytes
/
string_generate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# Function Generate two output strings depending upon
# occurrence of character in input string
from collections import Counter
def generateStrings(input):
# convert string into dictionary
# having characters as keys and frequency as value
freqDict = Counter(input)
# separate out characters having frequency 1 and more than 1
freq1 = [ key for (key,count) in freqDict.items() if count==1]
freqMore1 = [ key for (key,count) in freqDict.items() if count>1]
# sort lists and concatenate characters
# with out space to print resultant strings
freq1.sort()
freqMore1.sort()
# print output strings
print ('String with characters occurring once:')
print (''.join(freq1))
print ('String with characters occurring multiple times:')
print (''.join(freqMore1))
# Driver program
if __name__ == "__main__":
input = "geeksforgeeks"
generateStrings(input)