python - Comparing a list of lists with a list to find similar numbers -
here tried:
my_tickets = [ [ 7, 17, 37, 19, 23, 43], [ 7, 2, 13, 41, 31, 43], [ 2, 5, 7, 11, 13, 17], [13, 17, 37, 19, 23, 43] ] def lotto_matches(xs, my_tickets): xi = 0 # used pick specific things lists yi = 0 # used pick specific things lists result = [] in my_tickets: # list of lists x in xs: # picks if my_tickets[i] == xs[x]: #not sure if statement suppose result.append() # don't know goes in parenthesis print (result) return (result) lotto_matches([42,4,7,11,1,13], my_tickets)
i trying write function takes list of tickets , draw, , returns list telling how many picks correct on each ticket.
it supposed return [1,2,3,1]
output wrong.
how can this?
you can use map
, intersection
this:
def lotto_matches(pick, my_tickets): result = map(lambda x: len(set(x).intersection(pick)), my_tickets) return result print lotto_matches([42,4,7,11,1,13], my_tickets)
where pick
ticket match.
if using python 3, map
returns iterator not want, you'll need
return list(result)
Comments
Post a Comment