How to manipulate slice and list in Python, go.

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Go code to traverse Slice, look for a slice, count.

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: = A. ([]int); OK {      if c, ok1: = i. (int); Ok1 {         for Indexc, V: = range B {            if v = = c {               return Indexc}}}   }   if b, OK: = A. ([]str ing); OK {      If c, Ok1: = I. (string); Ok1 {         for indexc, V: = range B {            if v = = c {               return Indexc            }         }      }   }   Return-1}

You can see that slice does not have a way to find an element in the go language above. I'm customizing a method

The Python code below is very concise.

A=[1,2,3,4,1]for B in a:    print (b) i=0while I <len (a):    print (a[i])    I=i+1#print (sorted (a)) way one sort a.sort () Print (a) print (A.index (3)) A.count (1)

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.