Applying an Asynchronous Function to a List of Numbers

This technical problem involves implementing a function that takes in a list of numbers and an asynchronous function, and returns a list of the results of the function applied to each number in the list.

Problem

Implement a function that takes in a list of numbers and an asynchronous function, and returns a list of the results of the function applied to each number in the list.
Input: [1, 2, 3], async_func
Output: [async_func(1), async_func(2), async_func(3)]

Solution

This solution is in Python. Our A.I. can create solutions in multiple languages.
by kayakane
import asyncio

async def async_func(x):
    await asyncio.sleep(1)
    return x

async def main():
    l = [1, 2, 3]
    tasks = [async_func(x) for x in l]
    results = await asyncio.gather(*tasks)
    print(results)

asyncio.run(main())

A.I. Evaluation of the Solution

The candidate's solution correctly implements the function and returns the expected output. The candidate uses the asyncio library to create asynchronous tasks and wait for them to complete. This is a good approach to solving the problem.

Evaluated at: 2023-01-30 00:15:35