how to replace a comma “,” with “||” in a list

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
3
down vote

favorite












I have a list of equations:



dene = x1== 0.2, x2== 0.4, x3==0.5;


I like to convert this list to a Rule:



iki=x3==0.5]//Flatten


which works. Since my list of equations is a very long list, I like to use Mathematica function.
I have two options to make "dene" a Rule: either Replace "==" with "->" or Substitute "," with "||". I could not do any of these options, although I spent sometime on the problem. I need your help.









share







New contributor




Tebernus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 6




    ToRules[Or @@ x1 == 0.2, x2 == 0.4, x3 == 0.5]?
    – J. M. is somewhat okay.♦
    4 hours ago






  • 4




    Rule @@@ x1 == 0.2, x2 == 0.4, x3 == 0.5 ?
    – AccidentalFourierTransform
    4 hours ago










  • Both answers work for me, though @Accidenta's answer is more compact.
    – Tebernus
    2 hours ago






  • 1




    I think it's good to point out here that replacing comma's in expressions is not possible in Mathematica. The comma is a delimiter in expressions and does not represent an infix notation for a system symbol (unlike, e.g., ; which is short for CompoundExpression). You can play games with pretty much everything else, but comma's are basically untouchable unless you start converting expressions back and forth between strings (which is generally not how you want to program). Instead, you always want to find out what heads you need to transform. And if you want to splice things, use Sequence.
    – Sjoerd Smit
    1 hour ago















up vote
3
down vote

favorite












I have a list of equations:



dene = x1== 0.2, x2== 0.4, x3==0.5;


I like to convert this list to a Rule:



iki=x3==0.5]//Flatten


which works. Since my list of equations is a very long list, I like to use Mathematica function.
I have two options to make "dene" a Rule: either Replace "==" with "->" or Substitute "," with "||". I could not do any of these options, although I spent sometime on the problem. I need your help.









share







New contributor




Tebernus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 6




    ToRules[Or @@ x1 == 0.2, x2 == 0.4, x3 == 0.5]?
    – J. M. is somewhat okay.♦
    4 hours ago






  • 4




    Rule @@@ x1 == 0.2, x2 == 0.4, x3 == 0.5 ?
    – AccidentalFourierTransform
    4 hours ago










  • Both answers work for me, though @Accidenta's answer is more compact.
    – Tebernus
    2 hours ago






  • 1




    I think it's good to point out here that replacing comma's in expressions is not possible in Mathematica. The comma is a delimiter in expressions and does not represent an infix notation for a system symbol (unlike, e.g., ; which is short for CompoundExpression). You can play games with pretty much everything else, but comma's are basically untouchable unless you start converting expressions back and forth between strings (which is generally not how you want to program). Instead, you always want to find out what heads you need to transform. And if you want to splice things, use Sequence.
    – Sjoerd Smit
    1 hour ago













up vote
3
down vote

favorite









up vote
3
down vote

favorite











I have a list of equations:



dene = x1== 0.2, x2== 0.4, x3==0.5;


I like to convert this list to a Rule:



iki=x3==0.5]//Flatten


which works. Since my list of equations is a very long list, I like to use Mathematica function.
I have two options to make "dene" a Rule: either Replace "==" with "->" or Substitute "," with "||". I could not do any of these options, although I spent sometime on the problem. I need your help.









share







New contributor




Tebernus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I have a list of equations:



dene = x1== 0.2, x2== 0.4, x3==0.5;


I like to convert this list to a Rule:



iki=x3==0.5]//Flatten


which works. Since my list of equations is a very long list, I like to use Mathematica function.
I have two options to make "dene" a Rule: either Replace "==" with "->" or Substitute "," with "||". I could not do any of these options, although I spent sometime on the problem. I need your help.







replacement





share







New contributor




Tebernus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.










share







New contributor




Tebernus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








share



share






New contributor




Tebernus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 4 hours ago









Tebernus

306




306




New contributor




Tebernus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Tebernus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Tebernus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







  • 6




    ToRules[Or @@ x1 == 0.2, x2 == 0.4, x3 == 0.5]?
    – J. M. is somewhat okay.♦
    4 hours ago






  • 4




    Rule @@@ x1 == 0.2, x2 == 0.4, x3 == 0.5 ?
    – AccidentalFourierTransform
    4 hours ago










  • Both answers work for me, though @Accidenta's answer is more compact.
    – Tebernus
    2 hours ago






  • 1




    I think it's good to point out here that replacing comma's in expressions is not possible in Mathematica. The comma is a delimiter in expressions and does not represent an infix notation for a system symbol (unlike, e.g., ; which is short for CompoundExpression). You can play games with pretty much everything else, but comma's are basically untouchable unless you start converting expressions back and forth between strings (which is generally not how you want to program). Instead, you always want to find out what heads you need to transform. And if you want to splice things, use Sequence.
    – Sjoerd Smit
    1 hour ago













  • 6




    ToRules[Or @@ x1 == 0.2, x2 == 0.4, x3 == 0.5]?
    – J. M. is somewhat okay.♦
    4 hours ago






  • 4




    Rule @@@ x1 == 0.2, x2 == 0.4, x3 == 0.5 ?
    – AccidentalFourierTransform
    4 hours ago










  • Both answers work for me, though @Accidenta's answer is more compact.
    – Tebernus
    2 hours ago






  • 1




    I think it's good to point out here that replacing comma's in expressions is not possible in Mathematica. The comma is a delimiter in expressions and does not represent an infix notation for a system symbol (unlike, e.g., ; which is short for CompoundExpression). You can play games with pretty much everything else, but comma's are basically untouchable unless you start converting expressions back and forth between strings (which is generally not how you want to program). Instead, you always want to find out what heads you need to transform. And if you want to splice things, use Sequence.
    – Sjoerd Smit
    1 hour ago








6




6




ToRules[Or @@ x1 == 0.2, x2 == 0.4, x3 == 0.5]?
– J. M. is somewhat okay.♦
4 hours ago




ToRules[Or @@ x1 == 0.2, x2 == 0.4, x3 == 0.5]?
– J. M. is somewhat okay.♦
4 hours ago




4




4




Rule @@@ x1 == 0.2, x2 == 0.4, x3 == 0.5 ?
– AccidentalFourierTransform
4 hours ago




Rule @@@ x1 == 0.2, x2 == 0.4, x3 == 0.5 ?
– AccidentalFourierTransform
4 hours ago












Both answers work for me, though @Accidenta's answer is more compact.
– Tebernus
2 hours ago




Both answers work for me, though @Accidenta's answer is more compact.
– Tebernus
2 hours ago




1




1




I think it's good to point out here that replacing comma's in expressions is not possible in Mathematica. The comma is a delimiter in expressions and does not represent an infix notation for a system symbol (unlike, e.g., ; which is short for CompoundExpression). You can play games with pretty much everything else, but comma's are basically untouchable unless you start converting expressions back and forth between strings (which is generally not how you want to program). Instead, you always want to find out what heads you need to transform. And if you want to splice things, use Sequence.
– Sjoerd Smit
1 hour ago





I think it's good to point out here that replacing comma's in expressions is not possible in Mathematica. The comma is a delimiter in expressions and does not represent an infix notation for a system symbol (unlike, e.g., ; which is short for CompoundExpression). You can play games with pretty much everything else, but comma's are basically untouchable unless you start converting expressions back and forth between strings (which is generally not how you want to program). Instead, you always want to find out what heads you need to transform. And if you want to splice things, use Sequence.
– Sjoerd Smit
1 hour ago











3 Answers
3






active

oldest

votes

















up vote
1
down vote



accepted










Much like @AccidentalFourierTransform's comment and @Pillsy's answer, you can also replace the heads but on all levels.



x1 == 0.2, x2 == 0.4, x3 == 0.5 /. Equal -> Rule



x1 -> 0.2, x2 -> 0.4, x3 -> 0.5




A multi-level example



Array[x[##] == ## &, 2, 2]
% /. Equal -> Rule



x[1, 1] == 1, 1, x[1, 2] == 1, 2, x[2, 1] == 2, 1,
x[2, 2] == 2, 2



x[1, 1] -> 1, 1, x[1, 2] -> 1, 2, x[2, 1] -> 2, 1,
x[2, 2] -> 2, 2







share|improve this answer



























    up vote
    4
    down vote













    Here is a simple function that does what I think you want.



    makeRules[p : _Equal ..] := Rule @@@ p


    Then



    dene = x1 == 0.2, x2 == 0.4, x3 == 0.5;
    makeRules[dene]



    x1 -> 0.2, x2 -> 0.4, x3 -> 0.5






    share|improve this answer




















    • All the answers work for me, your as well. For my purpose, a simple replacement rule was needed. Your answer is much more advanced than I need but a nice structural solution.
      – Tebernus
      2 hours ago










    • @Tebernus. In practice, it will often be simpler just to write Rule @@@ ... but you said in your question that you would like a function.
      – m_goldberg
      2 hours ago










    • Yes, in my text I used a wrong term "function", with which I meant any solution in layman's language. Since I am not a programmer, I possibly misinformed experts in this area. Sorry for that. Regards, Tebernus
      – Tebernus
      51 mins ago

















    up vote
    3
    down vote













    This is a good use for Cases with a level specification, which allows you to use rules and pattern matching to create rules! The level spec helps if you have deeper nesting of Or expressions:



    expr = x1 == 0.2 || x2 == 0.4 || x3 == 0.5;

    Cases[expr, lhs_ == rhs_ :> lhs -> rhs, Infinity]
    (* x1 -> 0.2, x2 -> 0.4, x3 -> 0.5 *)





    share|improve this answer




















    • This is a good answer for pattern recognition.
      – Tebernus
      2 hours ago










    Your Answer




    StackExchange.ifUsing("editor", function ()
    return StackExchange.using("mathjaxEditing", function ()
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
    );
    );
    , "mathjax-editing");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "387"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );






    Tebernus is a new contributor. Be nice, and check out our Code of Conduct.









     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f182769%2fhow-to-replace-a-comma-with-in-a-list%23new-answer', 'question_page');

    );

    Post as a guest






























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote



    accepted










    Much like @AccidentalFourierTransform's comment and @Pillsy's answer, you can also replace the heads but on all levels.



    x1 == 0.2, x2 == 0.4, x3 == 0.5 /. Equal -> Rule



    x1 -> 0.2, x2 -> 0.4, x3 -> 0.5




    A multi-level example



    Array[x[##] == ## &, 2, 2]
    % /. Equal -> Rule



    x[1, 1] == 1, 1, x[1, 2] == 1, 2, x[2, 1] == 2, 1,
    x[2, 2] == 2, 2



    x[1, 1] -> 1, 1, x[1, 2] -> 1, 2, x[2, 1] -> 2, 1,
    x[2, 2] -> 2, 2







    share|improve this answer
























      up vote
      1
      down vote



      accepted










      Much like @AccidentalFourierTransform's comment and @Pillsy's answer, you can also replace the heads but on all levels.



      x1 == 0.2, x2 == 0.4, x3 == 0.5 /. Equal -> Rule



      x1 -> 0.2, x2 -> 0.4, x3 -> 0.5




      A multi-level example



      Array[x[##] == ## &, 2, 2]
      % /. Equal -> Rule



      x[1, 1] == 1, 1, x[1, 2] == 1, 2, x[2, 1] == 2, 1,
      x[2, 2] == 2, 2



      x[1, 1] -> 1, 1, x[1, 2] -> 1, 2, x[2, 1] -> 2, 1,
      x[2, 2] -> 2, 2







      share|improve this answer






















        up vote
        1
        down vote



        accepted







        up vote
        1
        down vote



        accepted






        Much like @AccidentalFourierTransform's comment and @Pillsy's answer, you can also replace the heads but on all levels.



        x1 == 0.2, x2 == 0.4, x3 == 0.5 /. Equal -> Rule



        x1 -> 0.2, x2 -> 0.4, x3 -> 0.5




        A multi-level example



        Array[x[##] == ## &, 2, 2]
        % /. Equal -> Rule



        x[1, 1] == 1, 1, x[1, 2] == 1, 2, x[2, 1] == 2, 1,
        x[2, 2] == 2, 2



        x[1, 1] -> 1, 1, x[1, 2] -> 1, 2, x[2, 1] -> 2, 1,
        x[2, 2] -> 2, 2







        share|improve this answer












        Much like @AccidentalFourierTransform's comment and @Pillsy's answer, you can also replace the heads but on all levels.



        x1 == 0.2, x2 == 0.4, x3 == 0.5 /. Equal -> Rule



        x1 -> 0.2, x2 -> 0.4, x3 -> 0.5




        A multi-level example



        Array[x[##] == ## &, 2, 2]
        % /. Equal -> Rule



        x[1, 1] == 1, 1, x[1, 2] == 1, 2, x[2, 1] == 2, 1,
        x[2, 2] == 2, 2



        x[1, 1] -> 1, 1, x[1, 2] -> 1, 2, x[2, 1] -> 2, 1,
        x[2, 2] -> 2, 2








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 31 mins ago









        That Gravity Guy

        1,047512




        1,047512




















            up vote
            4
            down vote













            Here is a simple function that does what I think you want.



            makeRules[p : _Equal ..] := Rule @@@ p


            Then



            dene = x1 == 0.2, x2 == 0.4, x3 == 0.5;
            makeRules[dene]



            x1 -> 0.2, x2 -> 0.4, x3 -> 0.5






            share|improve this answer




















            • All the answers work for me, your as well. For my purpose, a simple replacement rule was needed. Your answer is much more advanced than I need but a nice structural solution.
              – Tebernus
              2 hours ago










            • @Tebernus. In practice, it will often be simpler just to write Rule @@@ ... but you said in your question that you would like a function.
              – m_goldberg
              2 hours ago










            • Yes, in my text I used a wrong term "function", with which I meant any solution in layman's language. Since I am not a programmer, I possibly misinformed experts in this area. Sorry for that. Regards, Tebernus
              – Tebernus
              51 mins ago














            up vote
            4
            down vote













            Here is a simple function that does what I think you want.



            makeRules[p : _Equal ..] := Rule @@@ p


            Then



            dene = x1 == 0.2, x2 == 0.4, x3 == 0.5;
            makeRules[dene]



            x1 -> 0.2, x2 -> 0.4, x3 -> 0.5






            share|improve this answer




















            • All the answers work for me, your as well. For my purpose, a simple replacement rule was needed. Your answer is much more advanced than I need but a nice structural solution.
              – Tebernus
              2 hours ago










            • @Tebernus. In practice, it will often be simpler just to write Rule @@@ ... but you said in your question that you would like a function.
              – m_goldberg
              2 hours ago










            • Yes, in my text I used a wrong term "function", with which I meant any solution in layman's language. Since I am not a programmer, I possibly misinformed experts in this area. Sorry for that. Regards, Tebernus
              – Tebernus
              51 mins ago












            up vote
            4
            down vote










            up vote
            4
            down vote









            Here is a simple function that does what I think you want.



            makeRules[p : _Equal ..] := Rule @@@ p


            Then



            dene = x1 == 0.2, x2 == 0.4, x3 == 0.5;
            makeRules[dene]



            x1 -> 0.2, x2 -> 0.4, x3 -> 0.5






            share|improve this answer












            Here is a simple function that does what I think you want.



            makeRules[p : _Equal ..] := Rule @@@ p


            Then



            dene = x1 == 0.2, x2 == 0.4, x3 == 0.5;
            makeRules[dene]



            x1 -> 0.2, x2 -> 0.4, x3 -> 0.5







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 2 hours ago









            m_goldberg

            82.3k869190




            82.3k869190











            • All the answers work for me, your as well. For my purpose, a simple replacement rule was needed. Your answer is much more advanced than I need but a nice structural solution.
              – Tebernus
              2 hours ago










            • @Tebernus. In practice, it will often be simpler just to write Rule @@@ ... but you said in your question that you would like a function.
              – m_goldberg
              2 hours ago










            • Yes, in my text I used a wrong term "function", with which I meant any solution in layman's language. Since I am not a programmer, I possibly misinformed experts in this area. Sorry for that. Regards, Tebernus
              – Tebernus
              51 mins ago
















            • All the answers work for me, your as well. For my purpose, a simple replacement rule was needed. Your answer is much more advanced than I need but a nice structural solution.
              – Tebernus
              2 hours ago










            • @Tebernus. In practice, it will often be simpler just to write Rule @@@ ... but you said in your question that you would like a function.
              – m_goldberg
              2 hours ago










            • Yes, in my text I used a wrong term "function", with which I meant any solution in layman's language. Since I am not a programmer, I possibly misinformed experts in this area. Sorry for that. Regards, Tebernus
              – Tebernus
              51 mins ago















            All the answers work for me, your as well. For my purpose, a simple replacement rule was needed. Your answer is much more advanced than I need but a nice structural solution.
            – Tebernus
            2 hours ago




            All the answers work for me, your as well. For my purpose, a simple replacement rule was needed. Your answer is much more advanced than I need but a nice structural solution.
            – Tebernus
            2 hours ago












            @Tebernus. In practice, it will often be simpler just to write Rule @@@ ... but you said in your question that you would like a function.
            – m_goldberg
            2 hours ago




            @Tebernus. In practice, it will often be simpler just to write Rule @@@ ... but you said in your question that you would like a function.
            – m_goldberg
            2 hours ago












            Yes, in my text I used a wrong term "function", with which I meant any solution in layman's language. Since I am not a programmer, I possibly misinformed experts in this area. Sorry for that. Regards, Tebernus
            – Tebernus
            51 mins ago




            Yes, in my text I used a wrong term "function", with which I meant any solution in layman's language. Since I am not a programmer, I possibly misinformed experts in this area. Sorry for that. Regards, Tebernus
            – Tebernus
            51 mins ago










            up vote
            3
            down vote













            This is a good use for Cases with a level specification, which allows you to use rules and pattern matching to create rules! The level spec helps if you have deeper nesting of Or expressions:



            expr = x1 == 0.2 || x2 == 0.4 || x3 == 0.5;

            Cases[expr, lhs_ == rhs_ :> lhs -> rhs, Infinity]
            (* x1 -> 0.2, x2 -> 0.4, x3 -> 0.5 *)





            share|improve this answer




















            • This is a good answer for pattern recognition.
              – Tebernus
              2 hours ago














            up vote
            3
            down vote













            This is a good use for Cases with a level specification, which allows you to use rules and pattern matching to create rules! The level spec helps if you have deeper nesting of Or expressions:



            expr = x1 == 0.2 || x2 == 0.4 || x3 == 0.5;

            Cases[expr, lhs_ == rhs_ :> lhs -> rhs, Infinity]
            (* x1 -> 0.2, x2 -> 0.4, x3 -> 0.5 *)





            share|improve this answer




















            • This is a good answer for pattern recognition.
              – Tebernus
              2 hours ago












            up vote
            3
            down vote










            up vote
            3
            down vote









            This is a good use for Cases with a level specification, which allows you to use rules and pattern matching to create rules! The level spec helps if you have deeper nesting of Or expressions:



            expr = x1 == 0.2 || x2 == 0.4 || x3 == 0.5;

            Cases[expr, lhs_ == rhs_ :> lhs -> rhs, Infinity]
            (* x1 -> 0.2, x2 -> 0.4, x3 -> 0.5 *)





            share|improve this answer












            This is a good use for Cases with a level specification, which allows you to use rules and pattern matching to create rules! The level spec helps if you have deeper nesting of Or expressions:



            expr = x1 == 0.2 || x2 == 0.4 || x3 == 0.5;

            Cases[expr, lhs_ == rhs_ :> lhs -> rhs, Infinity]
            (* x1 -> 0.2, x2 -> 0.4, x3 -> 0.5 *)






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 4 hours ago









            Pillsy

            12.2k13178




            12.2k13178











            • This is a good answer for pattern recognition.
              – Tebernus
              2 hours ago
















            • This is a good answer for pattern recognition.
              – Tebernus
              2 hours ago















            This is a good answer for pattern recognition.
            – Tebernus
            2 hours ago




            This is a good answer for pattern recognition.
            – Tebernus
            2 hours ago










            Tebernus is a new contributor. Be nice, and check out our Code of Conduct.









             

            draft saved


            draft discarded


















            Tebernus is a new contributor. Be nice, and check out our Code of Conduct.












            Tebernus is a new contributor. Be nice, and check out our Code of Conduct.











            Tebernus is a new contributor. Be nice, and check out our Code of Conduct.













             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f182769%2fhow-to-replace-a-comma-with-in-a-list%23new-answer', 'question_page');

            );

            Post as a guest













































































            Comments

            Popular posts from this blog

            Long meetings (6-7 hours a day): Being “babysat” by supervisor

            Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

            Confectionery