How to replace, in a list, all the 1 by 15 and all the 0 by 5


    Aug 26 2012 | 6:11 pm
    Hello,
    How to replace, in a list, all the 1 by 15 and all the 0 by 5 ?
    exemple : get 5 5 15 15 5 5 from 0 0 1 1 0 0
    Best regards
    All

    • Aug 26 2012 | 6:49 pm
      Here's a fairly concise solution using vexpr. But in general, for finding/replacing, regexp is very powerful, and if you're comfortable with JavaScript you can accomplish such tasks quite well with js.
    • Aug 26 2012 | 6:58 pm
      In my opinion a regular expression (regexp object) is the easiest way to do this:
    • Aug 26 2012 | 7:31 pm
      I read the OP's desired task backward. If the incoming list is known to contain only 0s and 1s, then regexp (à la ShelLuser's solution) is the way to go. Or "vexpr $i1*15-10".
    • Aug 27 2012 | 6:09 am
      why not just [scale 0 1 5 15] ??
    • Aug 27 2012 | 10:39 am
      I don't think scale is such a good idea because it would change everything in the list. Including values which don't need to be changed.
      Although the OP doesn't mention the presence of anything else in the list I do think its an option to keep in mind.
    • Aug 27 2012 | 10:47 am
      [scale] still wins:
      Also I'm somehow only just now discovering the [routepass] object. It is my new favorite thing.
    • Aug 27 2012 | 10:53 am
      Ooh, I also didn't think about using zl.group like that. Learnin' new stuff erryday.
    • Aug 27 2012 | 1:39 pm
      Than you for your help.
      I can progress in my project...
      All