Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #102693 > unrolled thread

Searching Sets (Lottery Results)

Started byMrPink <tdsimpson@gmail.com>
First post2016-02-08 13:45 -0800
Last post2016-02-09 06:04 -0800
Articles 3 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  Searching Sets (Lottery Results) MrPink <tdsimpson@gmail.com> - 2016-02-08 13:45 -0800
    Re: Searching Sets (Lottery Results) Chris Angelico <rosuav@gmail.com> - 2016-02-09 11:04 +1100
      Re: Searching Sets (Lottery Results) MrPink <tdsimpson@gmail.com> - 2016-02-09 06:04 -0800

#102693 — Searching Sets (Lottery Results)

FromMrPink <tdsimpson@gmail.com>
Date2016-02-08 13:45 -0800
SubjectSearching Sets (Lottery Results)
Message-ID<6afb7298-6da7-44f9-847e-9603554c2f09@googlegroups.com>
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()
#################################

[toc] | [next] | [standalone]


#102698

FromChris Angelico <rosuav@gmail.com>
Date2016-02-09 11:04 +1100
Message-ID<mailman.115.1454976306.2317.python-list@python.org>
In reply to#102693
On Tue, Feb 9, 2016 at 8:45 AM, MrPink <tdsimpson@gmail.com> wrote:
> 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.
>

This suggests that there is an order to the numbers on your ticket
(you want to print them out in the same order), but not to the winning
numbers, which are simply a set. The easiest way to handle that would
be to iterate over your numbers, asking "if number in
winning_numbers:", and printing out a "match" marker if it is or a
"non-match" marker if it isn't.

ChrisA

[toc] | [prev] | [next] | [standalone]


#102722

FromMrPink <tdsimpson@gmail.com>
Date2016-02-09 06:04 -0800
Message-ID<09c7f060-e01f-48ff-a02d-b5ba1f52f41a@googlegroups.com>
In reply to#102698
On Monday, February 8, 2016 at 7:05:24 PM UTC-5, Chris Angelico wrote:
> On Tue, Feb 9, 2016 at 8:45 AM, MrPink wrote:
> > 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.
> >
> 
> This suggests that there is an order to the numbers on your ticket
> (you want to print them out in the same order), but not to the winning
> numbers, which are simply a set. The easiest way to handle that would
> be to iterate over your numbers, asking "if number in
> winning_numbers:", and printing out a "match" marker if it is or a
> "non-match" marker if it isn't.
> 
> ChrisA

Thanks Chris.  Very good point.  I was just too deep in the weeds to see that simple solution.  I was overthinking it.  ;-)

Sincerely,

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web