Slice operations in python and GO, instance code in list mode, and pythonslice
Instance code for operating slice and list in python and GO
GO code traverses the slice, searches for a specific slice, and counts the number.
Type Element interface {} func main () {a: = [] int {1, 2, 3, 4, 1} for _, I: = range a {fmt. println (I)} for I: = 0; I <len (a); I ++ {// fmt. println (I)} fmt. println (index0 (a, 3) fmt. println (index0 ([] string {"a", "B", "c", "d", "e"}, "e") sort. ints (a) // sort fmt. println (a)} // func index0 (a Element, I interface {}) int {if B, OK: =. ([] int); OK {if c, ok1: = I. (int); ok1 {for indexC, v: = range B {if v = c {return indexC }}} if B, OK: =. ([] string); OK {if c, ok1: = I. (string); ok1 {for indexC, v: = range B {if v = c {return indexC }}} return-1}
We can see that slice in the GO language is not looking for a specific element. Custom Method
The following python code is very concise
A = [1, 2, 3, 4, 1] for B in a: print (B) I = 0 while I <len (a): print (a [I]) I = I + 1 # print (sorted (a) method 1 sort. sort () print (. index (3). count (1)
Thank you for reading this article. I hope it will help you. Thank you for your support for this site!