2019-04-12 11:58:03 +03:00
|
|
|
|
// Copyright © 2018 Inanc Gumus
|
|
|
|
|
// Learn Go Programming Course
|
|
|
|
|
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
|
|
|
|
//
|
2019-10-30 19:34:44 +03:00
|
|
|
|
// For more tutorials : https://learngoprogramming.com
|
|
|
|
|
// In-person training : https://www.linkedin.com/in/inancgumus/
|
|
|
|
|
// Follow me on twitter: https://twitter.com/inancgumus
|
2019-04-12 11:58:03 +03:00
|
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func main() {
|
2019-05-04 20:35:25 +03:00
|
|
|
|
// args := os.Args[1:]
|
|
|
|
|
// if len(args) != 1 {
|
|
|
|
|
// fmt.Println("[english word] -> [turkish word]")
|
|
|
|
|
// return
|
|
|
|
|
// }
|
|
|
|
|
// query := args[0]
|
|
|
|
|
|
|
|
|
|
// #1: Nil Map: Read-Only
|
2019-04-12 11:58:03 +03:00
|
|
|
|
var dict map[string]string
|
|
|
|
|
|
2019-05-04 20:35:25 +03:00
|
|
|
|
// #5: You cannot assign to a nil map.
|
2019-04-12 11:58:03 +03:00
|
|
|
|
// dict["up"] = "yukarı"
|
|
|
|
|
// dict["down"] = "aşağı"
|
|
|
|
|
|
2019-05-04 20:35:25 +03:00
|
|
|
|
// #2: Map retrieval is O(1) — on average.
|
2019-04-12 11:58:03 +03:00
|
|
|
|
key := "good"
|
2019-05-04 20:35:25 +03:00
|
|
|
|
|
2019-04-12 11:58:03 +03:00
|
|
|
|
value := dict[key]
|
|
|
|
|
fmt.Printf("%q means %#v\n", key, value)
|
2019-05-04 20:35:25 +03:00
|
|
|
|
|
|
|
|
|
// #1B
|
|
|
|
|
fmt.Printf("# of Keys: %d\n", len(dict))
|
|
|
|
|
|
|
|
|
|
// fmt.Printf("Zero Value: %#v\n", dict)
|
|
|
|
|
|
|
|
|
|
// #4: Nil map ready to use
|
|
|
|
|
// if dict != nil {
|
|
|
|
|
// value := dict[key]
|
|
|
|
|
// fmt.Printf("%q means %#v\n", key, value)
|
2019-04-12 11:58:03 +03:00
|
|
|
|
// }
|
|
|
|
|
|
2019-05-04 20:35:25 +03:00
|
|
|
|
// #3: Cannot use non-comparable types as map key types
|
2019-04-12 11:58:03 +03:00
|
|
|
|
// var broken map[[]int]int
|
|
|
|
|
// var broken map[map[int]string]bool
|
|
|
|
|
//
|
|
|
|
|
// A map can only be compared to nil value
|
|
|
|
|
// _ = dict == nil
|
|
|
|
|
}
|