def smallest(X, k):
"""
Return the k smallest elements from X.
"""
h = []
for x in X:
if len(h) < k:
heapq.heappush(h, -x)
elif -x > h[0]:
heapq.heapreplace(h, -x)
return [-x for x in h]