Quantcast
Viewing latest article 3
Browse Latest Browse All 4

Answer by Vitaliy Kaurov for Adding elements to some sublists of unequal length

Perhaps something like this:

ReplacePart[a, #1 -> Append[a[[#1]], #2]& @@@ b]

If data are large and speedup is needed you might want to try Join

ReplacePart[a, #1 -> Join[a[[#1]], {#2}] & @@@ b]

In case you want value of a to be the new list with added elements, you whether can use AppendTo:

ReplacePart[a, #1 -> AppendTo[a[[#1]], #2] & @@@ b]

or simply reassign:

a = ReplacePart[a, #1 -> Append[a[[#1]], #2] & @@@ b]

Viewing latest article 3
Browse Latest Browse All 4

Trending Articles