Skip to content

Commit 65d4b10

Browse files
committed
finish one 4 kyu
1 parent 78c1c5b commit 65d4b10

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

[4 kyu]Strip Comments.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#import string
2+
def solution(string,markers):
3+
4+
stringSplit = string.split('\n')
5+
6+
def stripSentence(s):
7+
afterStrip = s
8+
for m in markers:
9+
if m in s and len(afterStrip) > len(s[:s.find(m)].rstrip()):
10+
afterStrip = s[:s.find(m)].rstrip()
11+
return afterStrip
12+
return '\n'.join([stripSentence(s) for s in stringSplit])
13+
14+
print(solution("apples, pears # and bananas\ngrapes\nbananas !apples", ["#", "!"]))
15+
print(solution("apples, pears # and bananas\ngrapes\nbananas !#apples", ["#", "!"]))
16+
#
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
def is_balanced(string, caps):
2+
for open,close in [(caps[i],caps[i+1]) for i in range(0,len(caps),2)]:
3+
print(open,close)
4+
for p in [c for c in string if c in caps]:
5+
pass
6+
7+
print(is_balanced('(Sensei [says) no!]','()[]'))

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy