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?


closed as off-topic by Bob Hanlon, corey979, Feyre, m_goldberg, MarcoB Dec 21 '16 at 22:34

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Bob Hanlon, corey979, Feyre, m_goldberg, MarcoB
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 4
    $\begingroup$ Did you want Riffle[#, "."] & /@ list ? $\endgroup$ – Simon Woods Nov 8 '16 at 21:04
  • 1
    $\begingroup$ Yes... Could you explain the difference in using Riffle[#, "."] & /@ list then Riffle[".", #] & /@ list ? And why Riffle[{"."}, #] & /@ list replaces with dots instead of "riffling"? $\endgroup$ – user305883 Nov 8 '16 at 21:29
  • $\begingroup$ Riffle[list, item] returns list with item inserted into the "gaps" between elements. If list is only one element long, there are no gaps, so list is returned unchanged. This is noted in the documentation for Riffle: Riffle[{e}, x] gives {e} $\endgroup$ – Simon Woods Nov 9 '16 at 16:53

As already commented by Simon Woods.

Here is the result using the examples given:

words = {{"Absolute risk reduction", 
   "Medicine"}, {"Absorption cross section", "Medicine"}, {"Abutment",
    "Dentistry", "Medicine"}}

{{"Absolute risk reduction", "Medicine"}, {"Absorption cross section", "Medicine"}, {"Abutment", "Dentistry", "Medicine"}}

Riffle[#, "."] & /@ words

{{"Absolute risk reduction", ".", "Medicine"}, {"Absorption cross section", ".", "Medicine"}, {"Abutment", ".", "Dentistry", ".", "Medicine"}}


Not the answer you're looking for? Browse other questions tagged or ask your own question.