-
Notifications
You must be signed in to change notification settings - Fork 0
/
Codewars_26.py
23 lines (23 loc) · 941 Bytes
/
Codewars_26.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#All that you can do on parenthesis
#creating parentheses
print([i for i in (list(map(lambda n: ''.join(n),list(permutations(s))))) if i.startswith('(') and i.endswith(')')])
['(())', '(())', '()()', '()()', '(())', '(())', '()()', '()()']
print(set([i for i in (list(map(lambda n: ''.join(n),list(permutations(s))))) if i.startswith('(') and i.endswith(')')]))
#function for calculating balanced parentheses
s='()()()()))))(((((('
def parentheses(s):
front=[]
back=[]
for i in list(s):
if i==('('):
front.append(i.count('('))
if i==(')'):
back.append(i.count(')'))
if (sum(front)+sum(back))%2==0:
print('True')
#one line approach for calculating balanced parentheses for .apply() and np.where
# across the dataframes in case of the codes
print((s.count('(')+s.count(')'))%2==0)
# across numpy
np.where((s.count('(')+s.count(')'))%2==0)
np['col'] = np['col'].str.contains=whatever condition true or false