Searching Sets (Lottery Results)

MrPink tdsimpson at gmail.com
Tue Feb 9 09:04:44 EST 2016


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,



More information about the Python-list mailing list