← 返回 coinbase 的题目列表Generate Objects Based on a Template
类型:online_judge
coinbase
Given a template dictionary, for example {'traitA':['AA','AB','AC'], 'traitB':['BA','BB','BC']}, write a program to generate a specified number of objects where each object's values are randomly selected from the template. The following requirements must be met:
The generated objects cannot have duplicate combinations.
Each value in the template has an associated rarity, where higher rarity means lower probability of being selected.
Write a complete program and run custom tests.
Example Test Case
Input: template {'traitA':['AA','AB','AC'], 'traitB':['BA','BB','BC']}, quantity 5
Output: [{'traitA':'AA', 'traitB':'BA'}, {'traitA':'AB', 'traitB':'BB'}, ...] (non-repeating, random results)
Example
Input
{'traitA':['AA','AB','AC'], 'traitB':['BA','BB','BC']} 5