Forum Discussion
Anonymous
6 years agoNot applicable
List.Unzip wanted
let suppose we have two lists for which I want to keep the correspondence in the order of the elements. So if I change the order of the first one of the lists, the elements of the second list also a...
- 6 years ago
Hi Anonymous
You can zip it again, this will reverse the zip, or am I missing something?
= List.Zip( List.Zip( { { 1, 2 }, { 3, 4 }, { 5, 6 } } ) )Best Regards,
Mariusz
If this post helps, then please consider Accepting it as the solution.
Please feel free to connect with me.
LinkedIn
Smauro
6 years agoSolution Sage
Well,
Now I've made a tweaked List.Zip:
(ListGiven as list) as list =>
let
n =
List.Max(
List.Transform(
ListGiven,
each try List.Count(_) otherwise 1
)
),
GetK =
(k) =>
List.RemoveFirstN(
List.RemoveLastN(
List.Transform(
ListGiven,
each try _{k} otherwise null
),
each _ = null
),
each _ = null
),
Zip =
List.Generate(
() =>
[
l =
List.RemoveFirstN(
List.RemoveLastN(
List.Transform(
ListGiven,
each try _{0} otherwise _
),
each _ = null
),
each _ = null
),
k = 1
],
each [k] <= n,
each
[
l = GetK([k]),
k = [k] + 1
],
each [l]
)
in
Zip
Contrary to List.Zip, it will also take single values, and cut leading and trailing nulls.
If you want to test it, you could name it fnListZip and use this:
let
l = {1,3,5,7,9},
k = {2,4,6},
#"ListZip(l)" = List.Zip({l}),
#"fnListZip(l)" = fnListZip({l}),
#"ListZip(k,l)" = List.Zip({k,l}),
#"fnListZip(k,l)" = fnListZip({k, l}),
#"ListZip(ListZip(k,l))" = List.Zip(#"ListZip(k,l)"),
#"fnListZip(fnListZip(k,l))" = fnListZip(#"fnListZip(k,l)"),
#"ListZip(l,k,l)" = List.Zip({l, k, l}),
#"fnListZip(l,k,l)" = fnListZip({l, k, l}),
#"ListZip(ListZip(l,k,l))" = List.Zip(#"ListZip(l,k,l)"),
#"fnListZip(fnListZip(l,k,l))" = fnListZip(#"fnListZip(l,k,l)"),
NotReallyAListZip = {{1,2},{3,4},{5,6},7,9},
#"ListZip(NotReallyAListZip)" = List.Zip(NotReallyAListZip),
#"fnListZip(NotReallyAListZip)" = fnListZip(NotReallyAListZip),
NotReallyAListZipB = {1,2,3,4,{5,"Here Is Something"},7,9},
#"ListZip(NotReallyAListZipB)" = List.Zip(NotReallyAListZipB),
#"fnListZip(NotReallyAListZipB)" = fnListZip(NotReallyAListZipB)
in
#"fnListZip(NotReallyAListZipB)"
Best,
Spyros