Better HN
topnewbestaskshowjobs
Log inSign up

pythongen

6 karma · joined May 7, 2017 (9y ago) · 1 submissions

Submissions

comment 9y ago · link · parent

your example sorted_breakfast doesn't work, in python 3.5 sorted_breakfast == None. Sort is a verb that modifies the receiving object, sorted is for returning a new object that is a sorted copy of the original, so you need to allocate two times the object.

Returning an iterator instead of a list has the advantage of not having to create a new object in case that is not needed, for example if you are going to filter a big dictionary just to obtain a few items then copying the keys of the dictionary and then filtering is not a good way of using memory efficiently.