blob: b0017610d978f92a8fdde9005d4d5ea4f7e5e4db (
plain)
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
|
def coin_change(S, m, n):
table = [[0 for x in range(m)] for x in range(n+1)]
for i in range(m):
table[0][i] = 1
for i in range(1, n+1):
for j in range(m):
x = table[i - S[j]][j] if i-S[j] >= 0 else 0
y = table[i][j-1] if j >= 1 else 0
table[i][j] = x + y
return table[n][m-1]
================
import re
def text_match_wordz_middle(text):
patterns = '\Bz\B'
if re.search(patterns, text):
return 'Found a match!'
else:
return('Not matched!')
text_match_wordz_middle('ciao')
==============
def max_occurrences(list1):
max_val = 0
result = list1[0]
for i in list1:
occu = list1.count(i)
if occu > max_val:
max_val = occu
result = i
return result
================
def sort_matrix(M):
result = sorted(M, key=sum)
return result
=================
def get_ludic(n):
ludics = []
for i in range(1, n + 1):
ludics.append(i)
return ludics
print(get_ludic(a*a))
=================
def adjac(ele, sub = []):
if not ele:
yield sub
else:
yield from [ idx for j in range(ele[0] - 1, ele[0] + 2)
for idx in adjac(ele[1:], sub + [j])
]
def get_coordinates(test_tup):
res = list(adjac(test_tup))
return (res)
===================
import heapq
def heap_sort(iterable):
h = []
for value in iterable:
heapq.heappush(h, value)
return [hq.heappop(h) for i in range(len(h))]
======================
def get_ludic(n):
ludics = []
for i in range(1, n + 1):
ludics.append(i)
index = 1
while(index != len(ludics)):
first_ludic = ludics[index]
remove_index = index + first_ludic
while(remove_index < len(ludics)):
ludics.remove(ludics[remove_index])
remove_index = remove_index + first_ludic - 1
index += 1
return ludics
print(get_ludic(a*a))
============================
from collections import defaultdict
def get_unique(test_list):
res = defaultdict(list)
for sub in test_list:
res[sub[1]].append(sub[0])
res = dict(res)
res_dict = dict()
for key in res:
res_dict[key] = len(list(set(res[key])))
return (str(res_dict))
|