def first matrix matrix return map sum zip def second string res for w

 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
def first(matrix):
m = matrix[1::2]
return map(sum, zip(*m))
def second(string):
res = 0
for word in string.split(' '):
l = len(word)
if l > res:
res = l
return res
from math import tan, pow, sin, cos
def ss(i, j):
a = pow(sin(i), 2) + pow(cos(j), 2)
b = (i - 5) / (j+1)
c = pow(a, b)
d = (i - 5) / (j+1.5)
f = 7.45 * tan(d)
return c + f
def generate_matrix(n, m):
column = []
for i in range(n):
row = []
for j in range(m):
row.append(ss(i, j))
column.append(row)
return column
def sum_of_rows(matrix):
res = []
for row in matrix:
r= sum(row)
res.append(r)
return res
def function(matrix):
max_element = max(max(row) for row in matrix)
result = []
for i in range(len(matrix)):
row = matrix[i]
result_row = []
for j in range(len(row)):
result_row.append(max_element - i*j)
result.append(result_row)
return result
# -------------
# - test -
# -------------
matrix = generate_matrix(3,3)
print matrix
print first(matrix)
row = 'sfsdfsd, sfsd f fsd f ffffff ss'
print second(row)
print sum_of_rows(matrix)
print function(matrix)