benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf d5550c3f-e418-5e9d-93b7-d907e8ea565a

Problem

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

complete prompt

from collections import OrderedDict
from prettytable import PrettyTable


def task_func(my_dict):
    """
    Sorts a given dictionary by its keys in ascending order and returns a PrettyTable object displaying the sorted items with the names 'Key' and 'Value'.

    Parameters:
    my_dict (dict): The dictionary to be sorted and displayed.

    Returns:
    PrettyTable: A PrettyTable object representing the sorted dictionary.

    Requirements:
    - collections.OrderedDict
    - prettytable.PrettyTable

    Examples:
    Display a simple dictionary in a sorted table format.
    >>> table = task_func({3: 'apple', 1: 'banana', 2: 'cherry'})
    >>> str(table).startswith('+') and 'banana' in str(table)
    True

    Display an empty dictionary.
    >>> str(task_func({})).startswith('+')
    True
    """

instruct prompt

Sorts a given dictionary by its keys in ascending order and returns a PrettyTable object displaying the sorted items with the names 'Key' and 'Value'. Display an empty dictionary. >>> str(task_func({})).startswith('+') True
The function should output with:
    PrettyTable: A PrettyTable object representing the sorted dictionary.
You should write self-contained code starting with:

Code

from collections import OrderedDict
from prettytable import PrettyTable
def task_func(my_dict):

code prompt

Code

from collections import OrderedDict
from prettytable import PrettyTable
def task_func(my_dict):

entry point

task_func

libs

  • collections
  • prettytable

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