Changing data structure to list of tuples