benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf dd8e4cb6-0f42-5747-84f9-99492a948e13

Problem

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

complete prompt

import re
import json
from collections import Counter


def task_func(json_str, top_n=10):
    """
    Extract all URLs from a string-serialized JSON dict using a specific URL pattern and return a dict
    with the URLs as keys and the number of times they appear as values.

    Parameters:
    json_str (str): The JSON string.
    top_n (int, Optional): The number of URLs to return. Defaults to 10. 

    Returns:
    dict: A dict with URLs as keys and the number of times they appear as values.

    Requirements:
    - re
    - json
    - collections.Counter

    Example:
    >>> task_func('{"name": "John", "website": "https://www.example.com"}')
    {'https://www.example.com': 1}
    """

instruct prompt

Extract all URLs from a string-serialized JSON dict using a specific URL pattern and return a dict with the URLs as keys and the number of times they appear as values.
The function should output with:
    dict: A dict with URLs as keys and the number of times they appear as values.
You should write self-contained code starting with:

Code

import re
import json
from collections import Counter
def task_func(json_str, top_n=10):

code prompt

Code

import re
import json
from collections import Counter
def task_func(json_str, top_n=10):

entry point

task_func

libs

  • collections
  • re
  • json

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