gpt4 book ai didi

F# 相当于 toLookup

转载 作者:行者123 更新时间:2023-12-01 00:01:25 25 4
gpt4 key购买 nike

鉴于此:

[
("A","A122");
("A","A123");
("B","B122");
("B","B123");
("C","C122");
]

是否有标准函数来获取此信息?

[
("A",["A122";"A123"]);
("B",["B122";"B123"]);
("C",["C122"])
]

我想到了Seq.distinctBy、List.partition、Set、Map,但似乎都不是我要找的。

谢谢...在我等待的时候,我会尝试自己动手:)

最佳答案

愚蠢的我,我没有注意到 Seq.groupBy!

[
("A","A122");
("A","A123");
("B","B122");
("B","B123");
("C","C122");
]
|> Seq.groupBy (fun (a, b) -> a)
|> Seq.map (fun (a, b) -> (a, Seq.map snd b))

输出:

seq
[("A", seq ["A122"; "A123"]); ("B", seq ["B122"; "B123"]);
("C", seq ["C122"])]

关于F# 相当于 toLookup,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1471316/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com