-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
59 lines (51 loc) · 1.2 KB
/
main.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
def descending(l):
lent= len(l)-1
r= True
if(len(l)==0):
return (r)
else:
for i in range(lent,0,-1):
if (l[i]>l[i-1]):
r= False
break
return (r)
def valley(l):
if(len(l)==0):
return(True)
if (len(l) < 4):
return (False)
if(l[0]<l[1]):
return(False)
for i in range(0,len(l)-1):
if(l[i]<l[i+1]):
pos=i
break
if(l[i]==l[i+1]):
return(False)
else:
return(False)
for i in range(pos,len(l)-1):
if(l[i]>=l[i+1]):
return(False)
return(True)
def transpose(m):
result = [[m[j][i] for j in range(len(m))] for i in range(len(m[0]))]
return (result)
import ast
def parse(inp):
inp = ast.literal_eval(inp)
return (inp)
fncall = input()
lparen = fncall.find("(")
rparen = fncall.rfind(")")
fname = fncall[:lparen]
farg = fncall[lparen+1:rparen]
if fname == "descending":
arg = parse(farg)
print(descending(arg))
if fname == "valley":
arg = parse(farg)
print(valley(arg))
if fname == "transpose":
arg = parse(farg)
print(transpose(arg))