Sorting in Python
interactivepython.org
interactivepython.org
Good, but then why does all your code say
temp = alist[i]
alist[i] = alist[j]
alist[j] = temp
And not alist[i], alist[j] = alist[j], alist[i]
It's confusing when you are trying to understand an algorithm, and the descriptions don't match the code.On the more general lines it seems like a quite pleasant book.
The reason we don't use a,b = b,a in our code is that it isn't very portable to other languages. We wrote this book as a second semester textbook. So most students are not very good programmers and will be transitioning to something like Java or C++ in the next semester.
Further, for most of the sorting algorithms we have exercises where we suggest that users modify the code themselves to use simultaneous assignment.
These kind of codes are not great for beginners because they tend to think that setting the flag is equivalent to exiting which is as you know an illusion.
Very well written, beginner friendly and great examples to demonstrate algos in action.
Thanks a ton to author for this gem :)
This is the way to learn things. Interactive, break things, try things and see how it actually works. Just donated to the cause and bookmarked the repo. Hope to contribute in future.