benchmarks.wiki / Public workspace
BigCodeBench / BigCodeBench v0.1.0_hf b5184609-a4c7-5136-891f-9506ea846282
Problem
Answer published by the source. Consult the official source to check your work against its answer.
complete prompt
import random
import string
from collections import defaultdict
def task_func(n, seed=None):
"""
Generate a dictionary with lists of random lowercase english letters.
Each key in the dictionary represents a unique letter from the alphabet,
and the associated value is a list, containing randomly generated instances
of that letter based on a seed.
The function randomly selects 'n' letters from the alphabet (a-z) and places each
occurrence in the corresponding list within the dictionary. The randomness is based
on the provided seed value; the same seed will produce the same distribution of letters.
The dictionary has only those keys for which a letter was generated.
Parameters:
n (int): The number of random letters to generate.
seed (int, optional): A seed value for the random number generator. If None, the randomness
is based on system time or the OS's randomness source.
Returns:
defaultdict: A dictionary where the keys are characters ('a' to 'z') and the values
are lists of randomly generated letters. Each list may have 0 to 'n' occurrences of
its associated letter, depending on the randomness and seed.
Requirements:
- collections.defaultdict
- random
- string
Example:
>>> task_func(5, seed=123)
defaultdict(<class 'list'>, {'b': ['b'], 'i': ['i'], 'c': ['c'], 'y': ['y'], 'n': ['n']})
>>> task_func(30, seed=1)
defaultdict(<class 'list'>, {'e': ['e'], 's': ['s'], 'z': ['z', 'z', 'z'], 'y': ['y', 'y', 'y', 'y'], 'c': ['c'], 'i': ['i', 'i'], 'd': ['d', 'd'], 'p': ['p', 'p', 'p'], 'o': ['o', 'o'], 'u': ['u'], 'm': ['m', 'm'], 'g': ['g'], 'a': ['a', 'a'], 'n': ['n'], 't': ['t'], 'w': ['w'], 'x': ['x'], 'h': ['h']})
"""
instruct prompt
Generate a dictionary with lists of random lowercase english letters. Each key in the dictionary represents a unique letter from the alphabet, and the associated value is a list, containing randomly generated instances of that letter based on a seed. The function randomly selects 'n' letters from the alphabet (a-z) and places each occurrence in the corresponding list within the dictionary. The randomness is based on the provided seed value; the same seed will produce the same distribution of letters. The dictionary has only those keys for which a letter was generated. >>> task_func(30, seed=1) defaultdict(<class 'list'>, {'e': ['e'], 's': ['s'], 'z': ['z', 'z', 'z'], 'y': ['y', 'y', 'y', 'y'], 'c': ['c'], 'i': ['i', 'i'], 'd': ['d', 'd'], 'p': ['p', 'p', 'p'], 'o': ['o', 'o'], 'u': ['u'], 'm': ['m', 'm'], 'g': ['g'], 'a': ['a', 'a'], 'n': ['n'], 't': ['t'], 'w': ['w'], 'x': ['x'], 'h': ['h']})
The function should output with:
defaultdict: A dictionary where the keys are characters ('a' to 'z') and the values
are lists of randomly generated letters. Each list may have 0 to 'n' occurrences of
its associated letter, depending on the randomness and seed.
You should write self-contained code starting with:
Code
import random
import string
from collections import defaultdict
def task_func(n, seed=None):
code prompt
Code
import random
import string
from collections import defaultdict
def task_func(n, seed=None):
entry point
task_func
libs
- collections
- random
- string
Discussion
No discussion posts on this page yet. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.
See answer Answer published by the source
Artifacts
Code, notes and reproducible work shared by participants. Files are served from a separate origin.
No artifacts on this page yet. Share reproducible code or notes in a contribution. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.
Source and history
initial import