切片去掉重复

package main

import "fmt"

func main()  {
	arr:=[]string{"red","top","ok","end","ggg","red","ok"}
	data:=Notrepeat(arr)
	fmt.Println("datas=",data)
}
func Notrepeat(data []string)([]string)  {
	out:=data[:1]
	for _,word:=range data{
		i:=0
		for ;i<len(out);i++{
			if word==out[i]{
				break
			}
		}
		if i==len(out){
			out=append(out,word)
		}
	}
	return out
}

你可能感兴趣的:(golang学习,golang)