Skip to content

Commit 48f22a2

Browse files
committed
Added Strings section of Python on G4G
1 parent 6ada448 commit 48f22a2

7 files changed

Lines changed: 44 additions & 0 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
def numberMatcher(str):
2+
pat=r'\d+'
3+
match=re.findall(pat,str) ##find all finds all the matched texts and returns a list
4+
if(match):
5+
for i in match:
6+
print(i, end=" ")
7+
else:
8+
print(-1,end="")
9+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
def validate(str):
2+
pat= r'^[a-z]+[!@#$%]+[0-9]+$'
3+
match=re.search(pat,str)
4+
if(match):
5+
return True
6+
else:
7+
return False
8+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
def combo_string(a, b):
2+
# your code here
3+
short = a if len(a) < len(b) else b
4+
longer = b if short == a else a
5+
6+
return short+longer+short
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
def join_middle(bound_by, tag_name):
2+
# complete the statement below to return the string as required
3+
return bound_by[0 : len(bound_by)//2] + tag_name + bound_by[len(bound_by) // 2 : ]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
def trim(str):
2+
return str.strip() # use str.strip() here to truncate all space lines
3+
def exists(str,istr):
4+
return str.find(istr) # use str.find(istr) to return 0 based index of the matched substring, else -1
5+
def titleIt(str):
6+
return str.title() # use str.title() to capitalize the first letter
7+
def casesSwap(str):
8+
return str.swapcase() # use str.swapcase() to swap the cases of lower to upper and upper to lower
9+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
def gfg(a):
2+
b = a.lower()
3+
if(b.startswith('gfg') and b.endswith('gfg')): # use b.startswith() and b.endswith()
4+
print ("Yes")
5+
else:
6+
print ("No")
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
def welcomeAboard(name):
2+
print ("Welcome " + name) # Your code here
3+

0 commit comments

Comments
 (0)