Timeline for How to replace the first occurence in an expression instead of replacing all?
Current License: CC BY-SA 3.0
6 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Sep 24, 2014 at 5:39 | comment | added | RunnyKine |
@WReach, good point, I forgot about FirstPosition
|
|
Sep 24, 2014 at 5:38 | comment | added | RunnyKine | @Mr.Wizard, thanks for the update, certainly cleaner :) | |
Sep 24, 2014 at 5:24 | comment | added | Mr.Wizard |
@WReach I was just updating the answer with that optimization. I considered using FirstPosition but it doesn't seem to bring much benefit here (a bit of clarity I guess) so I used the general equivalent.
|
|
Sep 24, 2014 at 5:22 | history | edited | Mr.Wizard | CC BY-SA 3.0 |
make code more efficient by searching only for the first occurrence rather than all
|
Sep 24, 2014 at 5:22 | comment | added | WReach |
+1 With version 10, we can use FirstPosition , e.g. HoldForm[x + 2 + 4 + x] // ReplacePart[#, FirstPosition[#, x] -> 4] & .
|
|
Sep 23, 2014 at 22:51 | history | answered | RunnyKine | CC BY-SA 3.0 |