Re:Key differences between Python 2.7.x and Python 3.x (2014)
by masklinn on Sunday May 07, 2017 @05:33PM
(#14287808)
> It is not "just because", it is because it returns a sorted list (which is exactly what you wanted), compared to returning None.
Also because `sorted()` works on any iterable, whereas .sort only works on lists.
Re:Key differences between Python 2.7.x and Python 3.x (2014)
by xapata on Monday May 08, 2017 @01:28AM
(#14289441)
I know that the best way to learn is "see one, do one, teach one" but I wish you'd put more effort into learning the language before teaching it.
The python.org tutorial and FAQ have answers to these questions.
I think it's unethical to tell a student, "just because" instead of, "I don't know why."
> breakfast = ["bacon", "eggs"]
> sorted_breakfast = breakfast.sort()
> works
Well, some of your students might point out to you that your `sorted_breakfast` is `None`, because that is what `sort()` returns, and even this example doesn't work as you have wanted ;)
On the other hand, if you have used `sorted(breakfast)` (and `sorted(breakfast.keys())` in other example), both examples would work as intended, and you couldn't blame Python 3.
> "Why is sorted() rather than sort()" - "just because."
It is not "just because", it is because it returns a sorted list (which is exactly what you wanted), compared to returning None.