1rows = 6 #Pattern(1,121,12321,1234321,123454321)
2for i in range(1, rows + 1):
3 for j in range(1, i - 1):
4 print(j, end=" ")
5 for j in range(i - 1, 0, -1):
6 print(j, end=" ")
7 print()
1import re
2# Compile a regular expression pattern into a regular expression object, which can be used for matching using its match(), search() and other methods, described below.
3
4prog = re.compile(pattern)
5result = prog.match(string)
6
7# is equivalent to
8
9result = re.match(pattern, string)
1import re
2
3pattern = '^a...s$'
4test_string = 'abyss'
5result = re.match(pattern, test_string)
6
7if result:
8 print("Search successful.")
9else:
10 print("Search unsuccessful.")
11
1if pattern := re.search("[iI] am (.*)", "I am tired"):
2 print(f"Hi {pattern.group(1)}, I'm dad!")
1def pattern(n):
2 for i in range(0,n):
3 for j in range(0, i+1):
4 print("* " , end="")
5 print("\r") pattern(5
1
2 python
3
4
5
6 import re
7v = "aeiou"
8c = "qwrtypsdfghjklzxcvbnm"
9print(*re.findall("(?=[%s]([%s]{2,})[%s])"%(c,v,c),input(), re.I) or [-1], sep="\n")
10