Python Data Structure Summary

Source: Internet
Author: User

First, List

1. List Script operator: Table

(1) Amplified operator:

"+": Used for combination lists; [1,2,3]+[4,5,6]==>[1,2,3,4,5,6]

"*": repeat; [2,3]*2==>[2,3,2,3]

2. List function

CMP (LIST1,LIST2): Compares elements of two lists, returns 1 when List1<list2, returns 1 when List1>list2, and returns 0 when List1=list2;

Len (list): Returns the number of list elements;

Max: Returns the maximum value of the list element;

Min (list): Returns the minimum value of the list element;

3. List method

(1) Amplification Method:

List.append (obj.): Adds a new object at the end of the list;

List.extend (seq): Appends all the elements of a list and tuple to the end of the list by appending multiple values of another sequence at one time (1, SEQ as list and tuple), and 2, when SEQ is a dictionary, adds all keys to the dictionary;)

List.insert (index,obj): Adds the object to the corresponding index position;

(2) Delete element:

List.pop ([obj=list[-1]): The last element in the list is deleted by default, and the value of the element is returned, List.pop (1) deletes the second-lowest element in the list;

List.remove (obj): Deletes the first occurrence of a value in the list;

(3) Number of statistics elements appearing in list: List.count (obj)

(4) Reverse list element: List.reverse ()

(5) Sort the original list: List.sort ([func])

4. The value of the access list:

List[index]: Access the index points to the value, starting from 0;

LIST[-1]: Access the last element of the countdown;

List[1:3]: Accesses the 2nd element to the 3rd element, the element with index 3 is not accessible;

List[1:]: Access the 2nd element to the last element.

5. Other:

Delete element statement: Del List[index]

Update element value: list[1]=3; ===> directly changes the value of the element indexed to 1 to "3"

Determine if an element value exists: 3 in [1,2,3]==> returns True

    

Python Data Structure Summary

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.