Here are some exercises for you to try on your own. Solutions are available at http://pragprog.com/titles/gwpy3/practical-programming.

  1. Write a function called find_dups that takes a list of integers as its input argument and returns a set of those integers occurring two or more times in the list.

  2. Write the bodies of the new versions of functions read_molecule and read_all_molecules from Creating New Type Annotations.

  3. Python’s set objects have a method called pop that removes and returns an arbitrary element from the set. If the set gerbils contains five cuddly little animals, for example, calling gerbils.pop() five times will return those animals one by one, leaving the set empty at the end. Use this to write a function called ...

Get Practical Programming, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.