-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprepinsta_L5.py
135 lines (134 loc) · 2.89 KB
/
prepinsta_L5.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#find length without len()
""" s='krupal'
c=0
for i in s:c+=1
print(c) """
#vowels
""" l=['a','e','i','o','u']
s='aeiou'
c=0
for s in s:
if s in l:
c+=1
print(c) """
#optimised
""" s='Krupal vinod vora'
s=s.lower()
dic={}
for i in "aeoiu":
c=s.count(i)
dic[i]=c
print(dic.values()) """
#remove vowels
""" l=['a','e','i','o','u']
s='krupalvora'
c=0
for i in s:
if i in l:
s=s.replace(i,'')
print(s) """
#string palni
""" s='kvgtvk'
if s==s[::-1]:print('palni') """
#removing character from string
""" s='a123asda54'
ans=list([i for i in s if i.isalpha() ])
ans=''.join(ans)
print(ans) """
#remove emmpty spaces
""" s='kru dfjs\n jkfs'
for i in s:
if i==' ':
s=s.replace(i,'')
if '\n' in s :
s=s.replace('\n','')
print(s) """
#remove brackets
""" s="[a+b(c/d)]"
for i in s:
if i=='[' or i==']' or i=='(' or i==')':
s=s.replace(i,"")
print(s) """
#sum of no in string
""" s='kru2jh45jn56'
sum=0
for i in s:
try:
int(i)
sum=sum+int(i)
except:
pass
print(sum)
"""
#capatilize first and last char of string
""" s='krupal vora'
s=s.split(' ')
s1=''
for i in s:
t=list(i)
t[0]=t[0].upper()
t[-1]=t[-1].upper()
i=''.join(t)
s1=s1+i+' '
print(s1) """
#freqof char
""" s='bagha'
dic={}
for i in s:
c=s.count(i)
dic[i]=c
print(dic.values)
print(dic['a']) """
#remove non repeating chars
""" s='fdfwkjfdsdjffh'
s=list(s)
dic={}
for i in s:
c=s.count(i)
dic[i]=c
print(dic)
s=''.join(s)
for i in s:
if dic[i]>1:
s=s.replace(i,'')
print(s) """
#replace sub string
""" string=input(“Enter String :\n“)
str1=input(“Enter substring which has to be replaced :\n“)
str2=input(“Enter substring with which str1 has to be replaced :\n“)
string=string.replace(str1,str2)
print(“String after replacement”)
print(string) """
#count common subsequence
""" n=input()
m=input()
l1,l2=len(n),len(m)
stri=[]
cnt=[[0 for i in range(l2+1)] for i in range(l1+1)]
for i in range(1,l1+1):
for j in range(1,l2+1):
if(n[i-1] == m[j-1]):
print(n[i],n[j])
print(n[i-1],n[j-1])
cnt[i][j] = 1 + cnt[i][j-1] + cnt[i-1][j]
else:
cnt[i][j] = cnt[i][j-1] + cnt[i-1][j] - cnt[i-1][j-1]
print(cnt,'\n',cnt[l1])
print(stri) """
#wildcard
"""
def solve(a,b):
n,m=len(a),len(b)
if n==0 and m==0:
return True
if n > 1 and a[0] == '*' and m == 0:
return False
if (n > 1 and a[0] == '?') or (n != 0 and m !=0 and a[0] == b[0]):
return solve(a[1:],b[1:])
if n !=0 and a[0] == '*':
return solve(a[1:],b) or solve(a,b[1:])
return False
str1=input('Enter string containing wild characters:\n')
str2=input('Enter string to be matched:\n')
print(solve(str1,str2))
"""