Concatenate Some Lists X36574


Statement
 

pdf   zip   main.py

html

Write a function cat_some(d, ks) that receives a dictionary d and a list of possible keys ks. The keys of d are integers. The values are lists of integers. The returned result must be the concatenation of the lists corresponding in d to the keys in ks, in the same order the corresponding keys appear in ks. Integers in ks that do not appear in d contribute an empty list to the result.

Observation

Please make sure to remove or comment out from the Jutge submission any doctesting code you might have in your source code.

Sample session
>>> cat_some({ 55: [0, 1, 4], 30: [-7, 7], 0: [0] }, [30, 55])
[-7, 7, 0, 1, 4]
>>> cat_some({ 55: [0, 1, 4], 30: [-7, 7], 0: [0], 2345: [ 23, 4, 56 ]  }, [ 0, 1, 2, 55, 0 ])
[0, 0, 1, 4, 0]
>>> cat_some({ 55: [0, 1, 4], 30: [0] }, [ 66, 55 ]) + cat_some({ 55: [0, 1, 4], 30: [0] }, [ 66, 55 ])
[0, 1, 4, 0, 1, 4]
>>> cat_some({ }, [ ])
[]
Information
Author
José Luis Balcázar
Language
English
Official solutions
Python
User solutions
Python