Searching for Lottery drawing list of ticket match...

MrPink tdsimpson at gmail.com
Fri Aug 12 16:47:40 EDT 2011


Boy, that was a lot more elegant that I would have thought.
Though hard for a greenhorn like me to really understand how the
assignment are working, etc.

Anyway, what are these kind of statement call so that I can read up
more on this?
What Python feature are you using?

  num_whites = ticket_whites & drawing_whites
  black_matching = ticket_black == drawing_black

Thanks,


On Aug 10, 11:35 pm, Miki Tebeka <miki.teb... at gmail.com> wrote:
> Python built in types are enough for this problem IMO. You can use sets of tuples to specify ticket and drawings and then just do set intersection.
>
> Say the drawing is set([(5, 'wb'), (1, 'wb'), (45, 'wb'), (23, 'wb'), (27, 'wb')]) (keeping black ball out). The you can create a score function:
>
> Side note: I might used a namedtuple to have drawing.whites, drawing.black.
>
> def score(ticket_whites, ticket_black, drawing_whites, drawing_black):
>     num_whites = ticket_whites & drawing_whites
>     black_matching = ticket_black == drawing_black
>     return {
>         (2, True)  : 1,
>         (3, False) : 2,
>         (3, True)  : 3,
>         (4, False) : 4,
>         (4, True)  : 5,
>         (5, False) : 6,
>         (5, True)  : 10
>     }[(num_whites, black_matching)]




More information about the Python-list mailing list