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
3# Regex Cheat sheet : https://www.dataquest.io/blog/regex-cheatsheet/
4# Regex python tester : https://pythex.org/
5# re doc : https://docs.python.org/3/library/re.html
6
7text = "i like train"
8reg = r"[a-c]" #the group of char a to c
9
10if re.match(reg, text): #Check if regex is correct
11 print(text)
12else:
13 print("Not any match")
1Find below are online regex tester
2
3https://regex101.com/
4https://pythex.org/
5http://www.pyregex.com/
6https://www.debuggex.com/
7
8Here you insert your regular expression and get the test result.
9Thank you !!!
1# exec lets us run strings as normal python code
2program = "print('Hello there!')"
3exec(program)
1import re
2s = 'I love books'
3var_name = 'love'
4result = re.search('(.+)'+var_name+'(.+)',s)
5print result
6var_name = 'hate'
7s2 = 'I hate books'
8result = re.search('(.+)'+var_name+'(.+)',s2)
9print result
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)