forked from leanprover/human-eval-lean
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHumanEval29.lean
More file actions
48 lines (34 loc) · 1 KB
/
HumanEval29.lean
File metadata and controls
48 lines (34 loc) · 1 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
module
def filterByPrefix (l : List String) (pref : String) : List String :=
l.filter (·.startsWith pref)
open Classical in
theorem filterByPrefix_eq {l : List String} {pref : String} :
filterByPrefix l pref = l.filter (fun s => pref.toList <+: s.toList) := by
simp [filterByPrefix, ← String.startsWith_string_iff]
/-!
## Prompt
```python3
from typing import List
def filter_by_prefix(strings: List[str], prefix: str) -> List[str]:
""" Filter an input list of strings only for ones that start with a given prefix.
>>> filter_by_prefix([], 'a')
[]
>>> filter_by_prefix(['abc', 'bcd', 'cde', 'array'], 'a')
['abc', 'array']
"""
```
## Canonical solution
```python3
return [x for x in strings if x.startswith(prefix)]
```
## Tests
```python3
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([], 'john') == []
assert candidate(['xxx', 'asd', 'xxy', 'john doe', 'xxxAAA', 'xxx'], 'xxx') == ['xxx', 'xxxAAA', 'xxx']
```
-/