benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf a7d62ae9-7f46-5ba5-a893-730d83eed460

Problem

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

complete prompt

import random
import string
import hashlib
import time


def task_func(data_dict: dict, seed=0) -> dict:
    """
    Process the given dictionary by performing the following operations:
    1. Add a key "a" with a value of 1.
    2. Generate a random salt of length 5 using lowercase ASCII letters.
    3. For each key-value pair in the dictionary, concatenate the value with the generated salt, 
       hash the concatenated string using SHA-256, and update the value with the hashed string.
    4. Add a 'timestamp' key with the current UNIX timestamp as its value.

    Parameters:
    data_dict (dict): The dictionary to be processed. Values should be string-convertible.
    seed (int, Optional): Seed value for the random number generator. Defaults to 0.

    Returns:
    dict: The processed dictionary with the hashed values and added keys.

    Requirements:
    - Uses the random, string, hashlib, and time libraries.

    Example:
    >>> task_func({'key': 'value'})["key"]
    '8691a011016e0fba3c2b0b8a26e4c9c722975f1defe42f580ab55a9c97dfccf8'

    """

instruct prompt

Process the given dictionary by performing the following operations: 1. Add a key "a" with a value of 1. 2. Generate a random salt of length 5 using lowercase ASCII letters. 3. For each key-value pair in the dictionary, concatenate the value with the generated salt, hash the concatenated string using SHA-256, and update the value with the hashed string. 4. Add a 'timestamp' key with the current UNIX timestamp as its value.
The function should output with:
    dict: The processed dictionary with the hashed values and added keys.
You should write self-contained code starting with:

Code

import random
import string
import hashlib
import time
def task_func(data_dict: dict, seed=0) -> dict:

code prompt

Code

import random
import string
import hashlib
import time
def task_func(data_dict: dict, seed=0) -> dict:

entry point

task_func

libs

  • hashlib
  • random
  • string
  • time

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