Question
PYTHON 3; DO NOT IMPORT ANY PACKAGES Please do all of number 2, thank you 2. a) Create a function that takes two lists (lst1
PYTHON 3; DO NOT IMPORT ANY PACKAGES
Please do all of number 2, thank you
2.
a)
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]
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], [])
[]
"""
# YOUR CODE GOES HERE #
b)
We define two strings (with any characters, case-sensitive) as siblings if we can rearrange all characters in one string to form the other. For instance, we can rearrange "aabbcde" to form "abedcba" since they have the same occurrences of characters, but we cannot rearrange abcdefg to xyzabcd.
Write a function that takes two strings and checks if they are siblings. Return True if they are, and False otherwise.
Hint: the solution can be in 1 (short) line.
def determine_siblings(str1, str2):
"""
>>> determine_siblings("abc", "cba")
True
>>> determine_siblings("friend", "aba")
False
>>> determine_siblings("ccc", "aba")
False
"""
# YOUR CODE GOES HERE #
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started