← run

he-012

0.000
0/1 tests· basic
Challenge · difficulty 2/5
# HumanEval/12

Implement a file **`solution.py`** that completes the function below. Keep the given name and signature; your file must define it at module level.

```python
from typing import List, Optional


def longest(strings: List[str]) -> Optional[str]:
    """ Out of list of strings, return the longest one. Return the first one in case of multiple
    strings of the same length. Return None in case the input list is empty.
    >>> longest([])

    >>> longest(['a', 'b', 'c'])
    'a'
    >>> longest(['a', 'bb', 'ccc'])
    'ccc'
    """
```

<!-- imported from OpenAI HumanEval (HumanEval/12) -->
tests/test_he_012.py
# Auto-generated from OpenAI HumanEval HumanEval/12. Do not edit by hand.
from solution import *  # noqa: F401,F403 (prompt helpers may be referenced by tests)
from solution import longest as candidate

METADATA = {
    'author': 'jt',
    'dataset': 'test'
}


def check(candidate):
    assert candidate([]) == None
    assert candidate(['x', 'y', 'z']) == 'x'
    assert candidate(['x', 'yyy', 'zzzz', 'www', 'kkkk', 'abc']) == 'zzzz'


def test_he_012():
    check(candidate)
Proposed solution
```python
def longest(strings: List[str]) -> str:
    """ Return None in case the input list is empty.
    >>> longest([]:
    >>> longest(['a', 'bb', 'ccc']):
        'a'
    >>> longest(['a', 'bb', 'ccc']):
        'a'
    >>> longest(['a', 'bb', 'ccc']):
        'a'
    >>> longest(['a', 'bb', 'ccc']):
        'a'
    >>> longest(['a', 'bb', 'ccc']):
        'a'
    >>> longest(['a', 'bb', 'ccc']):
        'a'
    >>> longest(['a', 'bb', 'ccc'])

Errors (stderr)

no code extracted from response