Forum Discussion
Dicken
2 years agoPost Prodigy
Inserting blank into a list ,
Hi, in the code below is there a way to deal with the fact the last value is not included, other than what i have don and let alist = { "a","a","a","a","b","b","b","b","c","c","c","d"} , ...
- 2 years ago
Please read post alist =
{ "a","a","a","a","b","b","b","b","c","c","c","d"} - 2 years ago
This perhaps?:
let alist = {"a","a","a","a","b","b","b","b","c","c","c","d"}, poslist = {1..List.Count(alist)-1} in List.Accumulate(poslist, {alist{0}}, (s,c)=> if alist{c} = alist{c-1} then s & {alist{c}} else s & {"",alist{c}})resulting in:
or use null instead of "".
slorin
2 years agoSuper User
Hi Dicken
Without List.Accumulate
= List.Combine(
List.Transform(
List.Zip({alist,List.Skip(alist)}),
each if _{0} = _{1} or _{1} = null then {_{0}} else {_{0}, ""})
)
or with your first idea
= let alist = { "a","a","a","a","b","b","b","b","c","c","c","d"} ,
poslist = { 0..List.Count( alist )-1} in
List.Accumulate( poslist, {}, (s,c)=>
if c=List.Max(poslist) or alist {c} = alist {c +1} then s & { alist {c} } else
s & { alist {c} , "" , List.last(alist)} )
Stéphane