Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Sorting in Python (interactivepython.org)
81 points by mathattack on June 11, 2014 | hide | past | favorite | 16 comments


"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.


Good 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.


Crawling 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.


If possible, what's the equivalent using bitwise operations?


I highly recommend this book to any intermediate Python programmer. This is the book that made me not to get scared whenever there comes thing called algorithms.

Very well written, beginner friendly and great examples to demonstrate algos in action.

Thanks a ton to author for this gem :)


I agree. This book taught me stacks, queues, deques, trees, and graphs. I was already exposed to searching/sorting and recursion from other resources, including John Zelle's "Python Programming: An Introduction to Computer Science" (2nd edition), which I recommend to any beginning Python programmer as a prelude to this one. It's perfect for self-teaching. Contact the publisher (same one, actually) for exercise answers and work through them all. I even emailed the author for a clarification and he responded with a thorough answer. Overall, a great learning experience that took my programming knowledge and skills to the next level.


This book is how I picked up algorithms and data structures having never gone through a formal computer science program. Glad to see it's still being worked on.


Thanks, I enjoy working on all aspects of this project. For anyone interested in helping us out you can find us on github.com/bnmnetp/runestone. I would love to have more contributors.


Oh I absolutely will. I've featured it heavily on Bento and its entire algorithms and data structures section is basically links to chapters in this book.


wow, I never knew about this. Love interactive learning materials like this. My daughter is going to be using this to learn Python and I will start with the turtle interactive program.

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.


Thanks for this! I spent a good amount of time learning from this just now. This is especially helpful to those self taught hackers who haven't really thought about/formally been introduced to these sorting techniques. I especially like all the interactive learning material. I hope for more!


You could also insert Timsort in the end, which is what python uses and a fabulous algorithm by Tim Peters.


Call me uneducated, but I always thought that since it featured so heavily in Python, it was named after this Tim. a https://www.youtube.com/watch?v=QDAeJ7eLGGg


no, this Tim would have been disastrous for the data!


Great idea. In other parts of the book we discuss how Python implements lists and other data structures, so that would fit in nicely with that theme.


I am glad I found this post and will be checking it out. Thanks.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: