Short way to apply a function to all elements in a list in golang

I would do exactly as you did, with a few tweaks to fix typos

import (
    "fmt"
    "strconv"
    "strings"
)

func main() {
    list := []int{1,2,3}

    var list2 []string
    for _, x := range list {
        list2 = append(list2, strconv.Itoa(x * 2))  // note the = instead of :=
    }

    str := strings.Join(list2, ", ")
    fmt.Println(str)
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)