-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplayground.py
116 lines (82 loc) · 2.35 KB
/
playground.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# # # # # #
# # # # # # ! Use connect-flash
# # # # # # *Reverse String
# # s = ["h", "e", "l", "l", "o"]
# # s.reverse()
# # # # # def reverse1(s):
# # # # # return s[::-1]
# # # # # def reverse2(s):
# # # # # l, r = 0, len(s) - 1
# # # # # while l < r:
# # # # # s[l], s[r] = s[r], s[l]
# # # # # l += 1
# # # # # r -= 1
# # # # # return s
# # # # # print(reverse1(s))
# # # # # print(reverse2(s))
# # # # # find prime numbers
# # # # # def is_prime(n):
# # # # # Linear search Algorithm:
# # # # import time
# # # # # def find_num(n, s):
# # # # # for i in range(len(s)):
# # # # # if s[i] == n:
# # # # # return f"Number {n} at index {i}"
# # # # # return f"Number {n} not found"
# # # # n = 13
# # # # s = [1, 8, 32, 91, 5, 15, 9, 100, 3]
# # # # # print(find_num(0, s))
# # # # def find_num(n, s):
# # # # for i in s:
# # # # if i == n:
# # # # return True
# # # # return False
# # # # start = time.time()
# # # # print(find_num(9, s))
# # # # end = time.time() - start
# # # # start2 = time.time()
# # # # print(9 in s)
# # # # end2 = time.time() - start2
# # # # print(
# # # # f"""
# # # # {end}
# # # # {end2}
# # # # """
# # # # )
# # # # Binary Search
# s = [1, 8, 32, 91, 5, 15, 9, 100, 3]
# s = sorted(s)
# print(s)
# # # def binary_search(s, n):
# # # s = sorted(s)
# # # print(s)
# # # l, r = 0, len(s) - 1
# # # while r >= l:
# # # mid = (l + r) // 2
# # # if s[mid] == n:
# # # return True
# # # else:
# # # if n < r:
# # # r = mid - 1
# # # else:
# # # l = mid + 1
# # # return False
# # # print(binary_search(s, 91))
# from bisect import bisect_left
# # # print(bisect_left(s, 98))
# def binary_search(a_list, target):
# index = bisect_left(a_list, target)
# print(index)
# if index <= len(a_list) - 1 and a_list[index] == target:
# return True
# return False
# print(binary_search(s, 100))
# # a = 300
# # b = 300
# # print(a is b)
# Names pattern pattern="[a-zA-Z]{3,24}"
# email pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,}$"
# phone pattern="7\\d\\d\\d\\d\\d\\d\\d\\d"
# NIN pattern="[a-zA-Z0-9_]{5,}"
# Address pattern="[A-Za-z0-9'\.\-\s\,]{5,}"
# password pattern="(?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).{6,}"