Skip to Main Content
The Statistics and Calculus with Python Workshop
book

The Statistics and Calculus with Python Workshop

by Peter Farrell, Alvaro Fuentes, Ajinkya Sudhir Kolhe, Quan Nguyen, Alexander Joseph Sarver, Marios Tsatsos, Amit Chaurasia, Rohan Chikorde, Sanjin Dedic, Tim Hoolihan, Ravi Ranjan Prasad Karn, Alberto Manzini
August 2020
Beginner to intermediate content levelBeginner to intermediate
740 pages
13h 41m
English
Packt Publishing
Content preview from The Statistics and Calculus with Python Workshop

Appendix

1. Fundamentals of Python

Activity 1.01: Building a Sudoku Solver

Solution

  1. First, we define the Solver class to store its input puzzle in its cells attribute, as follows:

    from copy import deepcopy

    class Solver:

        def __init__(self, input_path):

            # Read in the input file and initialize the puzzle

            with open(input_path, 'r') as f:

                lines = f.readlines()

            self.cells = [list(map(int, line.split(','))) \

                          for line in lines]

  2. The helper method that prints out the puzzle in a nice format can loop through the individual cells in the puzzle while inserting the separating characters '-' and '|' at the appropriate places:

        # Print out the initial puzzle or solution in a nice format.

        def display_cell(self): ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Math Adventures with Python

Math Adventures with Python

Peter Farrell

Publisher Resources

ISBN: 9781800209763Supplemental Content