Slice operations in python and GO, instance code in list mode, and pythonslice

Source: Internet
Author: User

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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.