I want to learn how to apply core functions with multiple parameters with no need to name new functions taking multiple variables.
I looked at Mapping multiple parameters of a function to specific values , How to Map a subset of list elements to a function? and would like to iterate to a list of lists.
This is my example.
I have a list of lists:
{{"Absolute risk reduction", "Medicine"}, {"Absorption cross section","Medicine"}, {"Abutment", "Dentistry", "Medicine"}}
I want to use Riffle[a, b] and apply
Riffle[{"Abutment", "Dentistry", "Medicine"}, "."]
for each of them, here b = "."
I can map a function with one parameter, but how to with multiple ones in one line?
Desired output:
{{"Abutment", ".", "Dentistry", ".", "Medicine"} .. }
I tried:
(* Map[Reverse, %180] is the lists of list evaluation *)
Riffle[{"."}, #] & /@ Map[Reverse, %180]
(* {{"."}, {"."}, {"."}}*)
Map[Riffle[{"."}, #] &, Map[Reverse, %180]]
(* {{"."}, {"."}, {"."}}*)
Riffle @@ {Map[Reverse, %180][[#]], {"."}} &
(* Riffle @@ {(Reverse /@ %180)[[#1]], {"."}} & *)
Why the first two returns a list of lists of dots and not the desired output?
Can you explain what is doing the third syntax?
Riffle[#, "."] & /@ list? – Simon Woods Nov 08 '16 at 21:04Riffle[#, "."] & /@ listthenRiffle[".", #] & /@ list? And whyRiffle[{"."}, #] & /@ listreplaces with dots instead of "riffling"? – user305883 Nov 08 '16 at 21:29Riffle[list, item]returnslistwithiteminserted into the "gaps" between elements. Iflistis only one element long, there are no gaps, solistis returned unchanged. This is noted in the documentation forRiffle: Riffle[{e}, x] gives {e} – Simon Woods Nov 09 '16 at 16:53