Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a function that takes two lists (lst1 and lst2), and finds all items in lst2 that also occur in lst1. Return all overlapping items

Create a function that takes two lists (lst1 and lst2), and finds all items in lst2 that also occur in lst1. Return all overlapping items in a list, whose items are in the same order as lst2 (i.e. items appear earlier in lst2 should also appear earlier in the returned list).

Note that this function should preserve all intersecting values as many times as they occur in both lists.

Examples (lst1, lst2 -> return):

[True, True], [False, False] -> []

[a, b, c, c], [c, c, d, e] -> [c, c]

[100, 200, 200, 300], [200, 300, 200, 200] -> [200, 300, 200]

[101.5], [101.5, 101.5, 101.5] -> [101.5]

[d, u, u, p], [p, u, u, u] -> [p, u, u]

CODE:

def find_intersection(lst1, lst2):

"""

>>> find_intersection([1, 2, 3, 4], [1, 2, 1, 2])

[1, 2]

>>> find_intersection(['a', 'b', 'c', 'c'], ['c', 'c', 'd', 'e'])

['c', 'c']

>>> find_intersection([1, 2, 3], [])

[]

"""

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Put Your Data To Work 52 Tips And Techniques For Effectively Managing Your Database

Authors: Wes Trochlil

1st Edition

0880343079, 978-0880343077

More Books

Students also viewed these Databases questions

Question

Which team solution is more likely to be pursued and why?

Answered: 1 week ago

Question

Why is the System Build Process an iterative process?

Answered: 1 week ago