This is a creation in Article, where the information may have evolved or changed.
Golang, the use of reflection and interface can do, no nonsense look at the code
Func Main () { b: = []string{"A", "B", "C", "C", "E", "F", "a", "G", "B", "B", "C"} sort. Strings (b) FMT. Println (Duplicate (b)) c: = []int{1, 1, 2, 4, 6, 7, 8, 4, 3, 2, 5, 6, 6, 8} sort. Ints (c) FMT. Println (Duplicate (c))}func Duplicate (A interface{}) (ret []interface{}) { VA: = reflect. ValueOf (a) for I: = 0; i < Va. Len (); i++ { If i > 0 && reflect. Deepequal (Va. Index (i-1). Interface (), Va. Index (i). Interface ()) { continue } ret = append (ret, Va. Index (i). Interface ()) } return ret}
Output:
[a B c E F g]
[1 2 3 4 5 6 7 8]
And Python's own system functions can do it.
A=["A", "B", "C", "C", "E", "F", "a", "G", "B", "B", "C"]print (list (set (a))) A=[1, 1, 2, 4, 6, 7, 8, 4, 3, 2, 5, 6, 6, 8]PR Int (list (set (a)))
Output:
[' E ', ' G ', ' B ', ' C ', ' A ', ' F ']
[1, 2, 3, 4, 5, 6, 7, 8]