-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUnique_Element_in_String.py
More file actions
37 lines (30 loc) · 929 Bytes
/
Unique_Element_in_String.py
File metadata and controls
37 lines (30 loc) · 929 Bytes
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
31
32
33
34
35
36
37
def unique():
'''create a python
function that takes a string and prints how many time each unique word exists in
the sentence'''
string = input("enter word :")
lis = list(string)
del_lis = []
unique_lis = []
for x in lis:
if x in del_lis:
pass
else:
del_lis.append(x)
unique_lis.append(lis.count(x))
lis.remove(x)
return f"unique_chr is {unique_lis} num of unique_chr is {len(unique_lis)} words"
stringuniq = unique()
print(stringuniq)
print(50*"*")
# enter word :AashutoshChauhan
# unique_chr is [1, 2, 2, 1, 4, 3, 1] num of unique_chr is 7 words
# **************************************************
def countDis():
string = input("enter word :")
# Stores all distinct characters
s = set(string)
# Return the size of the set
return f" num of unique_chr is {len(s)}"
stringuniq = countDis()
print(stringuniq)