next(it) returns the next iteration element each time it calls:
>>> list1=[3,1,2] >>> it = iter(list1) >>> print next(it) 3 >>> print next(it) 1 >>> print next(it) 2
key is a function that is called for each list item for comparison.
sorted() : If you do not specify the key parameter, it compares the values of the element; if you provide the key , it uses the result of calls to key functions to compare between the elements of the list.
So, for "zero" it is 3 , for "two" - 1 , for "one" - 2 . Since 1 < 2 < 3 , the result is ["two", "one", "zero"] .
source share