-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patha10q3.py
More file actions
48 lines (31 loc) · 1001 Bytes
/
a10q3.py
File metadata and controls
48 lines (31 loc) · 1001 Bytes
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
#!/usr/bin/env python
# coding: utf-8
# In[4]:
import check
from typing import *
def slowfunc(oldlist: List[int]) -> List[int]:
"""Do what it does with oldlist."""
ans = []
for i in range(2):
extralist = oldlist[:]
for i in range(len(extralist)):
x = extralist.pop(0)
ans = ans + [x, x**2]
return ans
check.expect("SF0", slowfunc([]), [])
check.expect("SF1", slowfunc([1]), [1,1,1,1])
def fastfunc(oldlist: List[int]) -> List[int]:
"""Do what slowfunc does with oldlist."""
ans = []
for i in range(len(oldlist)):
x = oldlist[i]
ans.append(x)
ans.append(x**2)
return ans + ans
check.expect("FF0", fastfunc([]), [])
check.expect("FF1", fastfunc([1]), [1,1,1,1])
check.expect("FF == SF 0", fastfunc([1, 1]), slowfunc([1, 1]))
l1= [1,2,3]
check.expect("mytest1", fastfunc(l1), [1, 1, 2, 4, 3, 9, 1, 1, 2, 4, 3, 9])
check.expect("mytest2", fastfunc(l1), slowfunc(l1))
# In[ ]: