3 ms·
"In Python exchange can be done in two simultaneous assignments" Good, but then why does all your code say temp = alist[i] alist[i] = alist[j] ali
by thomasahle 12y ago
"In Python exchange can be done in two simultaneous assignments"
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.
- bnmnetp 12y agoGood point. Although we do introduce the long way first. 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.
- javafoo 12y agoCrawling your book, i stumble over several codes that use flags instead of "return" to exit, by example, you use two flags for searching on an ordered list. 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.
- zatkin 12y agoIf possible, what's the equivalent using bitwise operations?