Re: Python teacher notes, preparing for class...

kirby urner <[email protected]>
Newsgroups gmane.comp.python.education
Message-ID <CAPJgG3SgTvC=BPBx0070bKNRCzRJbJ-r1MuB6YvDXSiyAQjKxQ@mail.gmail.com>
On Thu, Aug 30, 2018 at 3:02 AM Wes Turner <[email protected]> wrote:

> > By default, the sorted function looks at the leftmost element of a tuple
> or other iterable, when sorting...
>
>
You're right, my presentation is unclear.  I'll fix it.

The way it reads, it seems like you're implying that sorted() does this:
>
>
Yes, and that's wrong.

> >>> 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?
>
>
next(obj) triggers obj.__next__() which in 2.7 is named next internally
i.e. isn't magic.

__next__ is the main driver of iterators e.g. for loops hit __next__ over
and over as they loop over whatever.

True, a list (iterable) doesn't have a  __next__, but a for loop implicitly
applies __iter__ (called by the iter function) which turns iterables into
iterators.

> These are misspelled:
>
> > comparitor
> > compartor
>
>
Will fix next.



> These are great:
> - http://www.scipy-lectures.org/intro/language/python_language.html
> -
> http://nbviewer.jupyter.org/github/jrjohansson/scientific-python-lectures/blob/master/Lecture-1-Introduction-to-Python-Programming.ipynb
>   - Something about sorted with a link to the docs would be a good
> addition.
>
>
Thanks.  Yes, I'll add some links to the docs as you suggest.  Great
feedback!

Actually as part of my class I'm showing them edu-sig and other python.org
lists, so we were actually viewing this conversation.  I'll extend that to
showing your corrections, as I want to demonstrate how the Python community
all teaches each other, is friendly and so on.

Kirby

_______________________________________________
Edu-sig mailing list
[email protected]
https://mail.python.org/mailman/listinfo/edu-sig
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.