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