-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCH2ex5.py
69 lines (52 loc) · 1.51 KB
/
CH2ex5.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from collections import Counter
class funString():
def __init__(self,string = ""):
self.string=string
def __str__(self):
return self.string
def size(self) :
return len(self.string)
def changeSize(self):
return self.string.swapcase()
def reverse(self):
str = ""
for i in self.string:
str = i + str
return str
def deleteSame(self):
pass
#find duplicate
WC = Counter(self.string)
str=''
strlist=[]
strlist[:0]=self.string
# Finding no. of occurrence of a character
# and get the index of it.
duplicate = []
for letter, count in WC.items():
if (count > 1):
duplicate.append(letter)
#delete duplicate
for i in range(0,len(duplicate)):
j=i+1
while j<len(strlist)-1:
check = duplicate[i]
tocheck = strlist[j]
if duplicate[i] == strlist[j]:
strlist.pop(j)
else:
j += 1
text=''
for i in strlist:
text = text+i
return text
str1,str2 = input("Enter String and Number of Function : ").split()
res = funString(str1)
if str2 == "1" :
print(res.size())
elif str2 == "2":
print(res.changeSize())
elif str2 == "3" :
print(res.reverse())
elif str2 == "4" :
print(res.deleteSame())