gpt4 book ai didi

iteration - 步进 D 中的范围

转载 作者:行者123 更新时间:2023-12-01 10:52:33 26 4
gpt4 key购买 nike

有没有办法在 D 范围内创建一个步骤?例如,在 python 中, 范围(1、10、2)给我

        [1, 3, 5, 7, 9]

1 .. 10 以内的所有赔率

有没有办法在 D 中使用 foreach 来做到这一点?

    foreach(x; 1 .. 10) {
}

我知道我可以使用 iota(start, end, step),但我也想在最开始添加一个 int,但我不知道如何将类型 Result 转换为 int。

最佳答案

链([2],iota(3,16,2));

chain懒惰地连接范围

或者您可以使用 filter!q{a==2||a&1}(iota(2,16));

关于iteration - 步进 D 中的范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17244195/

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