Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def andy(a, b):
- inverse_a = {}
- for k,v in a.items():
- inverse_a[v.lower()] = str(k)
- # ^ v remove these lower() calls for case sensitivity
- return {k: [inverse_a.get(item.lower(), item) for item in v] for k,v in b.items()}
- #Andy K's test case
- a = {1: "Vue network", 2: "Blockbuster"}
- b = {1: ['Mann theater','LA','vue network'], 2 : ['Apollo Theatre', 'NY', 'Blockbuster']}
- expected_output = {1: ['Mann theater','LA','1'], 2 : ['Apollo Theatre', 'NY', '2']}
- assert andy(a,b) == expected_output
- #Kevin's test cases
- #basic usage
- assert andy(
- {1: "a", 2: "b"},
- {3: ["x", "y", "a"], 4: ["u", "v", "b"]}
- ) == {3: ["x", "y", "1"], 4: ["u", "v", "2"]}
- #case insensitivity
- assert andy(
- {1: "a", 2: "b"},
- {3: ["X", "Y", "A"], 4: ["U", "V", "B"]}
- ) == {3: ["X", "Y", "1"], 4: ["U", "V", "2"]}
- #if b has no matches, return a plain copy of b
- assert andy(
- {1: "foo", 2: "bar"},
- {3: ["x", "y", "a"], 4: ["u", "v", "b"]}
- ) == {3: ["x", "y", "a"], 4: ["u", "v", "b"]}
- #if a is empty: same behavior as "b has no matches"
- assert andy(
- {},
- {3: ["x", "y", "a"], 4: ["u", "v", "b"]}
- ) == {3: ["x", "y", "a"], 4: ["u", "v", "b"]}
- #replacements can occur at any point in the list
- assert andy(
- {1: "a", 2: "b"},
- {3: ["a", "y", "z"], 4: ["u", "b", "w"]}
- ) == {3: ["1", "y", "z"], 4: ["u", "2", "w"]}
- #multiple replacements are possible
- assert andy(
- {1: "a", 2: "b"},
- {3: ["a", "a", "a"], 4: ["a", "b", "a"]}
- ) == {3: ["1", "1", "1"], 4: ["1", "2", "1"]}
- #if a has duplicate values, ignore all but the last one
- assert andy(
- {1: "a", 2: "a"},
- {3: ["x", "y", "a"], 4: ["u", "v", "a"]}
- ) == {3: ["x", "y", "2"], 4: ["u", "v", "2"]}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement