benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 494363b4-b1cf-597f-87c7-b20f87161059

Problem

Answer published by the source. Consult the official source to check your work against its answer.

complete prompt

import random
from collections import Counter
from statistics import mode


def task_func(list_length=1000, range_start=1, range_end=10, random_seed=None):
    """
    Generate a random list of integers within a specified range. Convert this
    list to a generator object that yields tuples. Each tuple contains a number
    from the list and its frequency. Additionally, find and return the mode of 
    the list.

    Parameters:
    - list_length (int): The length of the random list to be generated. Default is 1000.
    - range_start (int): The start of the range for random numbers. Default is 1.
    - range_end (int): The end of the range for random numbers. Default is 10.
    - random_seed (int): Seed for the rng. Default is None.

    Returns:
    tuple: A tuple containing:
    - int: The mode of the generated list.
    - generator: A generator object yielding tuples with each number from the list and its frequency.

    Requirements:
    - random
    - collections
    - statistics

    Example:
    >>> mode, numbers = task_func(100, 1, 5, random_seed=1)
    >>> print(mode)  # prints the mode e.g. 3
    4
    >>> print(next(numbers))  # prints a tuple like (1, 25)
    (2, 18)

    >>> mode, numbers = task_func(20, -12, 334, random_seed=23)
    >>> print(mode)
    136
    >>> print([_ for _ in numbers])
    [(136, 1), (30, 1), (-4, 1), (291, 1), (145, 1), (204, 1), (182, 1), (259, 1), (171, 1), (54, 1), (86, 1), (124, 1), (215, 1), (-5, 1), (101, 1), (305, 1), (220, 1), (0, 1), (42, 1), (31, 1)]
    """

instruct prompt

Generate a random list of integers within a specified range. Convert this list to a generator object that yields tuples. Each tuple contains a number from the list and its frequency. Additionally, find and return the mode of the list. >>> mode, numbers = task_func(20, -12, 334, random_seed=23) >>> print(mode) 136 >>> print([_ for _ in numbers]) [(136, 1), (30, 1), (-4, 1), (291, 1), (145, 1), (204, 1), (182, 1), (259, 1), (171, 1), (54, 1), (86, 1), (124, 1), (215, 1), (-5, 1), (101, 1), (305, 1), (220, 1), (0, 1), (42, 1), (31, 1)]
The function should output with:
    tuple: A tuple containing:
    int: The mode of the generated list.
    generator: A generator object yielding tuples with each number from the list and its frequency.
You should write self-contained code starting with:

Code

import random
from collections import Counter
from statistics import mode
def task_func(list_length=1000, range_start=1, range_end=10, random_seed=None):

code prompt

Code

import random
from collections import Counter
from statistics import mode
def task_func(list_length=1000, range_start=1, range_end=10, random_seed=None):

entry point

task_func

libs

  • statistics
  • collections
  • random

Discussion

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

Official source

initial import