maps
This commit is contained in:
parent
f88a392425
commit
ce7565827e
|
|
@ -3,7 +3,6 @@ package main
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"main/sub"
|
"main/sub"
|
||||||
"os"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func jp (mylist ...int) {
|
func jp (mylist ...int) {
|
||||||
|
|
@ -13,10 +12,10 @@ func jp (mylist ...int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
args := os.Args[1]
|
// args := os.Args[1]
|
||||||
res := sub.Kek(args)
|
// res := sub.Kek(args)
|
||||||
fmt.Println(res)
|
// fmt.Println(res)
|
||||||
|
res := sub.Kek("data.txt")
|
||||||
jp(1,2,3,4)
|
jp(res...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
9
headFirst/maps/data.txt
Normal file
9
headFirst/maps/data.txt
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
Alexander
|
||||||
|
Alexey
|
||||||
|
Andrew
|
||||||
|
Vitaly
|
||||||
|
Alexander
|
||||||
|
Vitaly
|
||||||
|
Sergey
|
||||||
|
Sergey
|
||||||
|
Alexander
|
||||||
3
headFirst/maps/go.mod
Normal file
3
headFirst/maps/go.mod
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
module main
|
||||||
|
|
||||||
|
go 1.24.5
|
||||||
18
headFirst/maps/main.go
Normal file
18
headFirst/maps/main.go
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"main/sub"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
counter := make(map[string]int)
|
||||||
|
|
||||||
|
ret := sub.Kek("data.txt")
|
||||||
|
for _,name := range ret {
|
||||||
|
counter[name]++
|
||||||
|
}
|
||||||
|
for key,val := range counter {
|
||||||
|
fmt.Println(key,val)
|
||||||
|
}
|
||||||
|
}
|
||||||
21
headFirst/maps/sub/sub.go
Normal file
21
headFirst/maps/sub/sub.go
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
package sub
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Kek(fileName string) []string {
|
||||||
|
var seg []string
|
||||||
|
file, err := os.Open(fileName)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("Cannot open file")
|
||||||
|
}
|
||||||
|
scanner := bufio.NewScanner(file)
|
||||||
|
for scanner.Scan() {
|
||||||
|
seg = append(seg, scanner.Text())
|
||||||
|
}
|
||||||
|
file.Close()
|
||||||
|
return seg
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user