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
Problem One: Exploring Lake Pend Oreille
Problem Two: Image Analysis
Problem Three: Eight Queens
Problem Four: Accessing Peripherals
Problem Five: Recursion and Directories
Problem Six: Building the Web
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.