Lazy sorting in python