benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf a8133752-1286-5692-a9d8-26718dabd91f

Problem

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

complete prompt

import re
import requests
import json
import csv
import os  

# Constants
API_URL = 'https://api.example.com/data'

def task_func(pattern):
    """
    Make a GET request to an API, extract data that matches a RegEx pattern, and write it to a CSV file.

    Parameters:
    pattern (str): The regex pattern to match.

    Returns:
    str: The absolute path to the CSV file containing matched data. If no data is matched, the file will be empty.

    Note:
    - The CSV file generated name is "matched_data.csv"
    - The JSON response from the GET request in the API contains a key named "data", from which the data is extracted.

    Requirements:
    - requests
    - json
    - csv
    - re
    - os

    Example:
    >>> task_func(r'\\\\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\\\\.[A-Z]{2,}\\\\b')
    '/absolute/path/to/matched_data.csv'
    >>> task_func(r'\\\\d{3}-\\\\d{2}-\\\\d{4}')  # For matching SSN format
    '/absolute/path/to/matched_data.csv'
    """

instruct prompt

Make a GET request to an API, extract data that matches a RegEx pattern, and write it to a CSV file.
Note that: The CSV file generated name is "matched_data.csv" The JSON response from the GET request in the API contains a key named "data", from which the data is extracted.
The function should output with:
    str: The absolute path to the CSV file containing matched data. If no data is matched, the file will be empty.
You should write self-contained code starting with:

Code

import re
import requests
import json
import csv
import os  
# Constants
API_URL = 'https://api.example.com/data'
def task_func(pattern):

code prompt

Code

import re
import requests
import json
import csv
import os  
# Constants
API_URL = 'https://api.example.com/data'
def task_func(pattern):

entry point

task_func

libs

  • requests
  • os
  • csv
  • 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