-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
57 lines (51 loc) · 1.09 KB
/
main.py
File metadata and controls
57 lines (51 loc) · 1.09 KB
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
def rainaverage(l):
a=[]
res=[]
ret=[]
for i in l:
l3=i[0]
a.append(l3)
b=list(set(a))
for y in b:
cun=0
sum=0
result=0
for z in l:
if (y==z[0]):
sum=sum+z[1]
cun+=1
result=sum/cun
res.append(result)
for j in range (len(b)):
to = (b[j],res[j])
ret.append(to)
return (sorted(ret))
def listtype(l):
return (type(l) == type([]))
def flatten(l):
a=[]
l2=[]
def flat(l1):
for i in l1:
if (listtype(i) == True):
flat(i)
else:
a.append(i)
return a
l2=flat(l)
return (l2)
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 == "rainaverage":
arg = parse(farg)
print(rainaverage(arg))
if fname == "flatten":
arg = parse(farg)
print(flatten(arg))