-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex_53.py
138 lines (93 loc) · 1.66 KB
/
ex_53.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
136
def aps(arr,t):
lnth=len(arr)
for i in range(0,lnth):
for j in range(i+1,lnth):
if arr[i]+arr[j]==t:
print(str(arr[i])+","+str(arr[j]))
(aps([4,5,3,6,1,8,7,3],9))
################
from collections import Counter
def ew(a):
d={}
for i in a:
d[i]=d.get(i,0)+1
return d
a=[1,2,3,4,5,4,3,2,1]
b=[1,2,3,4]
a.extend(b)
res=ew(a)
print(res)
for i in res:
if res[i]==1:
print(i)
#########Largest continous sum########
def large_sum(lst):
max_sum=current_sum=0
for num in lst[1:]:
current_sum=max(current_sum+num,num)
max_sum=max(current_sum,max_sum)
return max_sum
print(large_sum([1,2,3,4,0,8]))
#################
sen=" This is best "
sen=sen.split()
lst=[]
for i in range(len(sen)-1,-1,-1):
lst.append(sen[i])
res=" ".join(lst)
print(res)
##############
import re
s="ABC12DEF3G56HIJ7ABC12"
res=[]
unq=set(s)
pattern=re.compile(r'([A-Z]+)([0-9]+)')
matches=pattern.finditer(s)
for i in matches:
print(i.group(1),'*',i.group(2))
######################
d={}
s="ABC"
flag=0
for i in s:
d[i]=d.get(i,0)+1
print(d)
res=[i for i in d.values() if i>1]
if res!=None:
print("nu")
else:
print("UNQ")
###################
s1="abbbggf"
#s1="aabbccd"
flag=0
s1=Counter(s1)
print(s1)
sl=[]
flag=0
for i in s1.values():
sl.append(i)
print(sl)
for i in sl:
if i>1:
flag=1
if flag==1:
print("no")
else:
print("yes")
##################
#another approach
s="abcd"
b=1
e=len(s)
f=0
while b<e:
if s[b]==s[b-1]:
f=1
break
else:
b+=1
if f==1:
print("NU")
else:
print("U")