Python Algorithms CHAPTER 4