Searching Sets (Lottery Results)

MrPink tdsimpson at gmail.com
Mon Feb 8 16:45:24 EST 2016


This is a continuation of my pursuit to learn Python. I have been tinkering with this for a number of years and I am back at it again.  I am stuck and need some guidance.

This is related to other posts that I have made in the past.  
For example: Searching for Lottery drawing list of ticket match: https://groups.google.com/forum/#!topic/comp.lang.python/sHLPrfmY3q4

I have a text file with the results of lottery drawing like so:
Draw Date   WB1 WB2 WB3 WB4 WB5 PB  PP
01/02/2016  42  15  06  05  29  10  2
12/30/2015  12  61  54  38  36  22  3
12/26/2015  65  40  44  59  27  20  2
12/23/2015  67  16  63  38  55  25  4
12/19/2015  30  68  59  41  28  10  2
12/16/2015  09  42  10  55  32  06  2
12/12/2015  62  02  30  19  14  22  2
12/09/2015  16  46  10  56  07  01  2
12/05/2015  47  33  68  27  13  13  2
12/02/2015  14  18  19  64  32  09  2
11/28/2015  47  02  66  67  06  02  3
11/25/2015  53  16  69  58  29  21  2
11/21/2015  37  57  47  50  52  21  3
11/18/2015  40  17  46  69  41  06  2
11/14/2015  66  37  22  14  45  05  3
11/11/2015  26  04  32  55  64  18  3
11/07/2015  50  53  07  16  25  15  2
11/04/2015  12  02  17  20  65  17  4
10/31/2015  09  47  20  25  68  07  2
10/28/2015  56  62  54  63  04  10  2
10/24/2015  20  31  56  64  60  02  3
10/21/2015  57  32  30  42  56  11  4

I load the lottery drawings into memory for searching with the following code although, it is incomplete.  I am stuck and need some guidance.

The set datatype seems to be the best for searching, but how best can I implement it?

And I want the results to highlight the numbers that were matched.  For example, if the white balls in the drawing are: 
"42 15 06 05 29"

AND the numbers on the lottery ticket are: 
"06 15 32 42 56"

THEN the display might look like: 
"06* 15* 32 42* 56" 

WHERE * signifies a match.

###############################
from datetime import datetime

class Powerball(object):
    """Summary of class here.

    Longer class information. . .Longer
    Attributes:
        fileName: File name to load drawing from.
    """
    # class Constants
    _DATE_FORMAT = '%m/%d/%Y'
    # class variables
    fileName = 'pb.txt'

    # class initialization
    def __init__(self, pFileName):
        """Return a Powerball Object with a set of winning drawings.
        :param pFileName:
        """
        self.fileName = pFileName

    # Open file and load drawing data sets.
    def readFileData(self):
        """File to open and load data from. """
        f = open(self.fileName, 'r')
        # read the whole file into a list of lines.
        lines = f.readlines()
        f.close()
        # For each line in the list of lines. . .
        for line in lines[1:50]:
            # split the string on whitespace into a list of strings
            fields = line.split()
            d = datetime.strptime(fields[0], self._DATE_FORMAT).date()
            # Use list comprehension to create a frozenset.
            wb = frozenset(int(num_str) for num_str in fields[1:6])
            pb = int(fields[6])
            t = tuple([wb, pb, d])
            # Store t into a data structure for searching later. . .
            # Not sure of best way to do this. . . 


p = Powerball("pb.txt")
p.readFileData()
#################################



More information about the Python-list mailing list