A lottery ticket contains five unique numbers. A set of unique numbers does not contain repeated elements. The winning combination of this lottery is chosen by picking five unique numbers. Define a function matches(ticket, winners) that takes two lists and returns an integer that says how many numbers the two lists have in common. In []: matches([11, 12, 13, 14, 15], [3, 8, 12, 13, 17]) Out[]: 2

Answer :

Parrain

Explanation:

You can use the SET INTERSECTION method.

Because intersection will give u the common elements.

And we can get their length by using len method.

Here is what the code would look like,

def matches(tickets, winner):

tickets = set(tickets)

winner = set(winner)

return len(tickets.intersection(winner))

Here is a shot to understand easier,

${teks-lihat-gambar} Parrain

Answer and Explanation:

def matches(tickets,winner):

tickets = set(tickets)

winner = set(winner)

counter = 0 #To Count the common elements

for i in tickets: # Iterate over all the elements in tickets.

if i in winner: # Check the element in the winner list

counter = counter+1

return counter

Other Questions