開発環境
- macOS High Sierra - Apple
- Emacs (Text Editor)
- Go (プログラミング言語)
- Introducing Go: Build Reliable, Scalable Programs Caleb Doxsey (著) (参考書籍)
入門 Python 3 (Bill Lubanovic (著)、斎藤 康毅 (監修)、長尾 高弘 (翻訳)、オライリージャパン)の4章(Pyの皮: コード構造)、4.13(復習問題)4-12.をGoで取り組んでみる。
コード(Emacs)
package main
import "fmt"
func main() {
titles := []string{
"Creature of Habit",
"Crewel Fate",
}
plots := []string{
"A nun turns into a monster",
"A haunted yarn shop",
}
movies := map[string]string{}
for i, _ := range titles {
movies[titles[i]] = plots[i]
}
fmt.Println(movies)
for k, v := range movies {
fmt.Println(k, ":", v)
}
}
入出力結果(Terminal)
$ go run sample6.go map[Creature of Habit:A nun turns into a monster Crewel Fate:A haunted yarn shop] Creature of Habit : A nun turns into a monster Crewel Fate : A haunted yarn shop $
0 コメント:
コメントを投稿