benchmarks.wiki / Public workspace
BigCodeBench / BigCodeBench v0.1.0_hf b1dfcfce-0fce-5db5-bed3-bf73b0766450
Problem
Answer published by the source. Consult the official source to check your work against its answer.
complete prompt
import json
import base64
from datetime import datetime
def task_func(data: dict, DATE_FORMAT = "%Y-%m-%d %H:%M:%S") -> str:
"""
Takes a Python dictionary, adds a current timestamp to it, serializes the modified dictionary
to a JSON-formatted string, and then encodes this string using base64 encoding with ASCII character encoding.
Parameters:
data (dict): The Python dictionary to encode. The dictionary should not contain a key named 'timestamp',
as this key is used to insert the current timestamp by the function. The input dictionary
is modified in-place by adding the 'timestamp' key.
Returns:
str: A base64 encoded string that represents the input dictionary with an added timestamp,
encoded in ASCII. The timestamp is added with the key 'timestamp'.
DATE_FORMAT: The timestamp format. Default to 'YYYY-MM-DD HH:MM:SS'.
Requirements:
- json
- base64
- datetime.datetime
Example:
>>> data = {'name': 'John', 'age': 30, 'city': 'New York'}
>>> encoded_data = task_func(data)
>>> isinstance(encoded_data, str)
True
"""
instruct prompt
Takes a Python dictionary, adds a current timestamp to it, serializes the modified dictionary to a JSON-formatted string, and then encodes this string using base64 encoding with ASCII character encoding.
The function should output with:
str: A base64 encoded string that represents the input dictionary with an added timestamp,
encoded in ASCII. The timestamp is added with the key 'timestamp'.
DATE_FORMAT: The timestamp format. Default to 'YYYY-MM-DD HH:MM:SS'.
You should write self-contained code starting with:
Code
import json
import base64
from datetime import datetime
def task_func(data: dict, DATE_FORMAT = "%Y-%m-%d %H:%M:%S") -> str:
code prompt
Code
import json
import base64
from datetime import datetime
def task_func(data: dict, DATE_FORMAT = "%Y-%m-%d %H:%M:%S") -> str:
entry point
task_func
libs
- base64
- json
- datetime
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