Function to convert list of dicts into long format