maps
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
Alexander
|
||||
Alexey
|
||||
Andrew
|
||||
Vitaly
|
||||
Alexander
|
||||
Vitaly
|
||||
Sergey
|
||||
Sergey
|
||||
Alexander
|
||||
@@ -0,0 +1,3 @@
|
||||
module main
|
||||
|
||||
go 1.24.5
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user