benchmarks.wiki / Public workspace
BigCodeBench / BigCodeBench v0.1.0_hf 839c0bb1-94f0-50f5-a14e-c9c798f3520c
Problem
Answer published by the source. Consult the official source to check your work against its answer.
complete prompt
import collections
from itertools import zip_longest
from random import choices
def task_func(l1, l2, K=10):
"""
Combine two lists by alternating their elements, even if they are of different lengths.
Elements from the longer list without a counterpart in the shorter one will be included on their own.
Then, create a random sample of size K from the combined list, and calculate the frequency of
each element in the sample.
Parameters:
l1 (list): The first list containing any hashable types.
l2 (list): The second list containing any hashable types.
K (int): the size of the random sample from the combined list. Default to 10.
Returns:
collections.Counter: An object that counts the frequency of each element in the sample.
Requirements:
- collections
- itertools.zip_longest
- random.choices
Example:
>>> import random
>>> random.seed(32)
>>> l1 = list(range(10))
>>> l2 = list(range(10, 20))
>>> freq = task_func(l1, l2)
>>> print(freq)
Counter({5: 2, 10: 1, 2: 1, 3: 1, 9: 1, 14: 1, 7: 1, 1: 1, 8: 1})
"""
instruct prompt
Combine two lists by alternating their elements, even if they are of different lengths. Elements from the longer list without a counterpart in the shorter one will be included on their own. Then, create a random sample of size K from the combined list, and calculate the frequency of each element in the sample.
The function should output with:
collections.Counter: An object that counts the frequency of each element in the sample.
You should write self-contained code starting with:
Code
import collections
from itertools import zip_longest
from random import choices
def task_func(l1, l2, K=10):
code prompt
Code
import collections
from itertools import zip_longest
from random import choices
def task_func(l1, l2, K=10):
entry point
task_func
libs
- collections
- random
- itertools
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