File tree Expand file tree Collapse file tree 1 file changed +57
-0
lines changed Expand file tree Collapse file tree 1 file changed +57
-0
lines changed Original file line number Diff line number Diff line change
1
+ def rainaverage (l ):
2
+ a = []
3
+ res = []
4
+ ret = []
5
+ for i in l :
6
+ l3 = i [0 ]
7
+ a .append (l3 )
8
+ b = list (set (a ))
9
+ for y in b :
10
+ cun = 0
11
+ sum = 0
12
+ result = 0
13
+ for z in l :
14
+ if (y == z [0 ]):
15
+ sum = sum + z [1 ]
16
+ cun += 1
17
+ result = sum / cun
18
+ res .append (result )
19
+ for j in range (len (b )):
20
+ to = (b [j ],res [j ])
21
+ ret .append (to )
22
+ return (sorted (ret ))
23
+
24
+ def listtype (l ):
25
+ return (type (l ) == type ([]))
26
+ def flatten (l ):
27
+ a = []
28
+ l2 = []
29
+ def flat (l1 ):
30
+ for i in l1 :
31
+ if (listtype (i ) == True ):
32
+ flat (i )
33
+ else :
34
+ a .append (i )
35
+ return a
36
+ l2 = flat (l )
37
+ return (l2 )
38
+ import ast
39
+
40
+ def parse (inp ):
41
+ inp = ast .literal_eval (inp )
42
+ return (inp )
43
+
44
+ fncall = input ()
45
+ lparen = fncall .find ("(" )
46
+ rparen = fncall .rfind (")" )
47
+ fname = fncall [:lparen ]
48
+ farg = fncall [lparen + 1 :rparen ]
49
+
50
+ if fname == "rainaverage" :
51
+ arg = parse (farg )
52
+ print (rainaverage (arg ))
53
+
54
+ if fname == "flatten" :
55
+ arg = parse (farg )
56
+ print (flatten (arg ))
57
+
You can’t perform that action at this time.
0 commit comments