In Haskell:
> import qualified Data.Map as M > import Data.List > m = M.fromList [(1,["a","b","c"]), (2,["d","e"]), (3,["f"])] > map M.fromList . transpose . map (\(i,xs) -> map ((,) i) xs) . M.toList $ m [fromList [(1,"a"),(2,"d"),(3,"f")],fromList [(1,"b"),(2,"e")],fromList [(1,"c")]]
M.toList and M.fromList convert the map to a list of association pairs and vice versa.
map ((,) i) xs coincides with [(i,x) | x<-xs] [(i,x) | x<-xs] , adding (i,...) to each element.
transpose swaps “rows” and “columns” in a list of lists, similar to transposing a matrix.
source share