Join Barron Stone for an in-depth discussion in this video Finding solutions with itertools, part of Code Clinic: Python.
In this video, we'll take a look at the section…of code that calculates solutions…to the n queens problem.…It's based on an example that Raymond Hettinger…posted on activestate.com which demonstrates…the power of the Python itertools module.…The itertools module provides a number of iterator…functions which can be used as efficient…building blocks for algorithms.…For this program, we'll specifically be using…the permutations function, and I'm going…to demonstrate that here using idle.…You can import the permutations function…from the itertools module by typing…from itertools import permutations.…
Now permutations takes as an input an object…such as a list.…Zero one two.…Using that list, it'll generate an iterable object…which returns every possible ordering…of elements in that list.…So you can see here we just get an object…back from our call to permutations.…So let me demonstrate how permutations can work…on that list by copying it.…We'll put this list inside of a for loop.…We'll print out every possible result returned…
Barron introduce challenges and provides an overview of his solutions in Python. Challenges include topics such as statistical analysis, searching directories for images, and accessing peripheral devices.
Visit other courses in the series to see how to solve the exact same challenges in languages like C#, C++, Java, PHP, and Ruby.
Skill Level Intermediate
Q: Why can't I access the Lake Pend Orielle site (http://lpo.dt.navy.mil)?
A: The Lake Pend Orielle site is not accessible in some geographical areas. We have contacted the owner of the server to try to resolve this issue.
Q: I am unable to access the Lake Pend Oreille data from outside the U.S.
A: A static copy of this data is provided here for lynda.com members outside of the U.S