next_smallest (humaneval-solutions/90.py)

agentic-awesome-skills · skills/loki-mode/benchmarks/results/2026-01-05-00-49-17/humaneval-solutions/90.py · python · MIT
testing, tag:knn-classified

Returns the second smallest unique integer from a list, or None if not available.

# Source: https://github.com/sickn33/agentic-awesome-skills | License: MIT | Copyright 2026 Antigravity User
# Provided via justclaw.it.com; keep this notice with the code.
def next_smallest(lst):
    """
    You are given a list of integers.
    Write a function next_smallest() that returns the 2nd smallest element of the list.
    Return None if there is no such element.
    
    next_smallest([1, 2, 3, 4, 5]) == 2
    next_smallest([5, 1, 4, 3, 2]) == 2
    next_smallest([]) == None
    next_smallest([1, 1]) == None
    """
    if len(lst) < 2:
        return None
    
    unique_sorted = sorted(set(lst))
    
    if len(unique_sorted) < 2:
        return None
    
    return unique_sorted[1]

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key