Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Go中的Python列表理解_Python_Go - Fatal编程技术网

Go中的Python列表理解

Go中的Python列表理解,python,go,Python,Go,我正在翻译下面的Python函数。它使用的是列表理解,我认为这在围棋中是不可用的。最好的翻译方法是什么 def list1s(): return ["10." + str(x) + "." + str(y) + ".1" for x in range(192, 256) for y in range(0, 256)] 只需使用显式for循环。然而,你不应该试图简单地把你在一种语言中所做的翻译成另一种语言 func list1s() []string { res := m

我正在翻译下面的Python函数。它使用的是列表理解,我认为这在围棋中是不可用的。最好的翻译方法是什么

def list1s():
        return ["10." + str(x) + "." + str(y) + ".1" for x in range(192, 256) for y in range(0, 256)]

只需使用显式for循环。然而,你不应该试图简单地把你在一种语言中所做的翻译成另一种语言

func list1s() []string {
    res := make([]string, 0, 256*64)
    for x := 192; x < 256; x++ {
        for y := 0; y < 256; y++ {
            res = append(res, fmt.Sprintf("10.%d.%d.1", x, y))
        }
    }
    return res
}
func list1s()[]字符串{
res:=make([]字符串,0,256*64)
对于x:=192;x<256;x++{
对于y:=0;y<256;y++{
res=append(res,fmt.Sprintf(“10.%d.%d.1”,x,y))
}
}
返回res
}

我想您建议避免语言间的简单翻译,这意味着这段代码在围棋中不是惯用的,是吗?老实说,好奇,我对围棋一无所知。但是当你用一种语言写作时,你必须考虑如何解决这种语言的问题,而不是用另一种语言,然后再翻译。