Searching Sets (Lottery Results)

Chris Angelico rosuav at gmail.com
Mon Feb 8 19:04:56 EST 2016


On Tue, Feb 9, 2016 at 8:45 AM, MrPink <tdsimpson at 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


More information about the Python-list mailing list