from typing import List
from typing import Dict
import torch


def list2dict(batched_inputs: List) -> Dict:
    """turn data from list to dict.

    Args:
        batched_inputs: input data

    Returns:
        Dict: a dict containing the input data
    """
    batch_size = len(batched_inputs)
    img_feats = torch.zeros((batch_size, *batched_inputs[0]['features'].shape),
                            dtype=batched_inputs[0]['features'].dtype)
    input_ids = torch.zeros((batch_size, *batched_inputs[0]['input_ids'].shape),
                            dtype=batched_inputs[0]['input_ids'].dtype)
    answers_scores = torch.zeros((batch_size, *batched_inputs[0]['answers_scores'].shape),
                                 dtype=batched_inputs[0]['answers_scores'].dtype)
    input_mask = torch.zeros((batch_size, *batched_inputs[0]['input_mask'].shape),
                             dtype=batched_inputs[0]['input_mask'].dtype)
    question_id = torch.zeros([batch_size], dtype=torch.int32)
    for idx in range(batch_size):
        img_feats[idx] = batched_inputs[idx]['features']
        input_ids[idx] = batched_inputs[idx]['input_ids']
        answers_scores[idx] = batched_inputs[idx]['answers_scores']
        input_mask[idx] = batched_inputs[idx]['input_mask']
        question_id[idx] = batched_inputs[idx]['question_id']

    batch_data = dict()

    batch_data['features'] = img_feats
    batch_data['input_ids'] = input_ids
    batch_data['answers_scores'] = answers_scores
    batch_data['input_mask'] = input_mask
    batch_data['question_id'] = question_id

    return batch_data