gpt4 book ai didi

erlang - 在 Erlang 中替换元组中的键

转载 作者:行者123 更新时间:2023-12-04 10:06:24 27 4
gpt4 key购买 nike

我有一个元组列表,例如。 [{1,40},{2,45},{3,54}....{7,23}] 其中 1...7 是一周中的天数(通过查找 calendar:day_of_the_week() 计算)。所以现在我想将列表更改为 [{Mon,40},{Tue,45},{Wed,54}...{Sun,23}]。有没有比列表更简单的方法:keyreplace?

最佳答案

...或使用不同的语法:

[{httpd_util:day(A), B} || {A,B} <- L]

在哪里:
L = [{1,40},{2,45},{3,54}....{7,23}]

该构造称为 list comprehension ,并读作:

"Build a list of {httpd_util:day(A),B} tuples, where {A,B} is taken from the list L"

关于erlang - 在 Erlang 中替换元组中的键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/157058/

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