From 7e2f3183974e1289d3197bc0eee77bb26579684f Mon Sep 17 00:00:00 2001 From: Inanc Gumus Date: Sun, 5 May 2019 19:04:27 +0300 Subject: [PATCH] add: map as sets example --- 23-input-scanning/02-map-as-sets/main.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/23-input-scanning/02-map-as-sets/main.go b/23-input-scanning/02-map-as-sets/main.go index 53670de..b66b0ed 100644 --- a/23-input-scanning/02-map-as-sets/main.go +++ b/23-input-scanning/02-map-as-sets/main.go @@ -24,21 +24,24 @@ func main() { in := bufio.NewScanner(os.Stdin) in.Split(bufio.ScanWords) - // index the words words := make(map[string]bool) for in.Scan() { words[in.Text()] = true } - // unnecessary - // if _, ok := words[query]; ok { - // ... - // } - - // answer the user query if words[query] { - fmt.Printf("The input contains %q word.\n", query) + fmt.Printf("The input contains %q.\n", query) return } - fmt.Printf("Sorry. The input does contain %q word.\n", query) + fmt.Printf("Sorry. The input does contain %q.\n", query) + + // query := "sun" + // fmt.Println("sun:", words["sun"], "tesla:", words["tesla"]) + + // unnecessary + // if _, ok := words[query]; ok { + // fmt.Printf("The input contains %q.\n", query) + // return + // } + // fmt.Printf("Sorry. The input does contain %q.\n", query) }