Compare elements and create lists