<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def collect(coro, index, results, preserve_order=False, return_exceptions=False):
 """ Collect is used internally to execute coroutines and collect the returned value. This function is intended to be used internally. """

    result = yield from safe_run(coro, return_exceptions=return_exceptions)

    if preserve_order:
        results[index] = result
    else:
        results.append(result)