> By default, the sorted function looks at the leftmost element of a tuple or other iterable, when sorting...
AFAIU, sorted() compares the whole object.
>>> l = [(3, 2), (3, 1), (1, 1, 2), (1, 1)]
>>> sorted(l)
[(1, 1), (1, 1, 2), (3, 1), (3, 2)]
The way it reads, it seems like you're implying that sorted() does this:
>>> l = [(3, 2), (3, 1), (1, 1, 2), (1, 1)]
>>> sorted(l, key=lambda x: x[0])
[(1, 1, 2), (1, 1), (3, 2), (3, 1)]
> You'll find some excellent overview of the magic methods in this essay by Rafe Kettler: A Guide to Python's Magic Methods. He's mostly looking at Python 2.7, so does not pick up on the __next__ method, however you'll be able to fill in the blanks thanks to this course
This is unclear to me. What does the next() function do? How do I find the docs and source for it?
These are misspelled:
> comparitor
> compartor
These are great:
- Something about sorted with a link to the docs would be a good addition.
IDK, I tend to find it much easier to just read the docs (and the source, if it's not clear).
sorted() is a built-in function (as indicated by the TypeError thrown by inspect.getfile(sorted)); which are in bltinmodule.c: