I've imported an Excel with 2 columns (Address and Final Address) which are both urls.

myimport = {{"Address", 
  "Final Address"}, 
aiutarti-a-scegliere-gli-infissi/"}, {"http://www.anekitalia.com/", 
  "https://www.anekitalia.com/"}, {"http://www.bagnochic.com/", 

Then I defined a pure function to match a List of 2 elements and Mapped it to all the elements of the list:

f[{a_, b_}] :=  SequenceAlignment[a, b]
Map[f, myimport[[All, 1 ;; 2]]]

Reading this answer I wanted to Apply to each element of the list a second function:

  sa /. {a_, b_} :> {Style[a, Red], "(", Style[b, Green], ")"}]]

sa is defined in the question that I've linked and it's just

sa = SequenceAlignment[text1, text2]

How can I combine f and the replacement copied from the answer?


1 Answer 1

f[{a_, b_}] := SequenceAlignment[a, b]

sa = Map[f, myimport[[All, 1 ;; 2]]];

Row[Flatten[sa /. {a_String, b_String} :>
    {Style[a, Red], "(", Style[b, Green], ")"}]]

Specifying the type (String) for a and/or b prevents the replacement applying to the overall lists.

Alternatively, with output as strings:

f[{a_, b_}] := StringJoin[SequenceAlignment[a, b] /. 
   {c_String, d_String} :>
    {ToString[Style[c, Red], StandardForm], "(",
     ToString[Style[d, Green], StandardForm], ")"}]

Column[Map[f, myimport[[All, 1 ;; 2]]]]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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