Reputation
2,180
Next privilege 2,500 Rep.
Create tag synonyms
Badges
8 34
Impact
~26k people reached

Dec
4
comment Insert at specific resulting positions in multidimensional list?
That doesn't work as I want. The position of y in {{1}, {2, x, 3, y, 4}, {3, 4}, {5, z}} is {2,4}, but I want it to be {2,3}. The output I expect from inserttt[{{1}, {2, 3, 4}, {3, 4}, {5}}, {x, y, z}, {{2, 2}, {2, 3}, {4, 2}}] is {{1},{2,x,y,3,4},{3,4},{5,z}}
Dec
4
comment Insert at specific resulting positions?
@DavidG.Stork Yes. As I explain in the answer, this method doesn't allow inserting multiple elements. It only inserts copies of the same element. Hence I obtain {x, 1, 2, 3, x, 4, 5}
Dec
4
comment Insert at specific resulting positions in multidimensional list?
@Kuba Typo. Fixed.
Dec
4
revised Insert at specific resulting positions in multidimensional list?
added 8 characters in body
Dec
4
comment Insert at specific resulting positions?
Sorry about that. I had a typo.
Dec
4
asked Insert at specific resulting positions in multidimensional list?
Dec
4
revised Insert at specific resulting positions?
added 30 characters in body
Dec
4
comment Insert at specific resulting positions?
@andre Thanks for pointing out that the positions list should be sorted ;)
Dec
4
comment Insert at specific resulting positions?
I think that insertF = Fold[Insert[#, #2[[1]], #2[[2]]] &, #, SortBy[Transpose[{#2, #3}], Last]] &; works.
Dec
4
comment Insert at specific resulting positions?
In think the Accumulate@#3 is the problem. Replacing it with just #3 works.
Dec
4
comment Insert at specific resulting positions?
The line of code Fold[Insert[#, #2[[1]], #2[[2]]] &, list0, {{a, 1}, {x,5}}] gives what I want. However the function insertF as you defined it doesn't. In your example with the function, x should be inserted at position 4 of the resulting list.
Dec
4
comment Insert at specific resulting positions?
@andre myInsert[list0,{a,x},{4,1}] should output {x,1,2,a,3,4,5}. The list of positions {4,1} gives the positions of the inserted elements in the resulting list.
Dec
4
comment Insert at specific resulting positions?
@DavidG.Stork I disagree. This produces the desired output (I am the OP ;)). Please tell me why you think this is not consistent with what I asked.
Dec
4
revised Insert at specific resulting positions?
added 67 characters in body
Dec
4
revised Insert at specific resulting positions?
added 52 characters in body
Dec
4
revised Insert at specific resulting positions?
added 52 characters in body
Dec
4
answered Insert at specific resulting positions?
Dec
4
asked Insert at specific resulting positions?
Nov
27
comment Plot a transformed distribution with an If function
How do you draw the vertical line joining the two pieces of Piecewise? Usually I just get a discontinuous plot. I'm studying your code but I don't see it.
Nov
26
comment What graph distributions are available in Mathematica?
@Szabolcs Yes, but it has directed random graphs, random trees. I expect Mathematica to include those too eventually.