Flatten all inner lists that do not have sublists
ReleaseHold[Flatten[MapAt[Hold, lis, Position[lis, _List?VectorQ]]]]
{a, b, {d, f}, c, k, {h, l}, e, {a}}
Apply[## &, lis, -3]
Apply[Sequence, lis, -3] (* thanks J.M. *)
Map[## & @@ # &, lis, -3]
Replace[lis, {a__} :> a, -3]
FlattenAt[#, Position[#, {__}, -3]]& @ lis
all give
{a, b, {d, f}, c, k, {h, l}, e, {a}}
Also, with
parts = Join @@ Most /@ Rest @ GatherBy[Position[lis, List], First];
you can use ReplacePart
,MapAt
, FlattenAt
or Part
assignment:
ReplacePart[lis, parts -> Sequence]
MapAt[Sequence &, lis, parts]
FlattenAt[lis, Most /@ parts]
Module[{l = #}, (l[[##]] = Sequence) & @@@ #2; l] &[lis, parts]
{a, b, {d, f}, c, k, {h, l}, e, {a}}
Finally, you can do in-place assignment:
(lis[[##]] = Sequence) & @@@ parts; lis
{a, b, {d, f}, c, k, {h, l}, e, {a}}