List summary in Python

Source: Internet
Author: User

1: List of lists definition:
A sequential, orderly sequence of numbers consisting of elements that can be any object (number, String, object, list), an element can be used for index lookups, and a linear data structure. Use [] to denote. The list is mutable and is an iterative object.

List specific definitions
l=[] (empty list) l=list (iterable)
The list cannot be defined at the start of a size. Specifies the size of the datagram type error (TYPEERROR).

2: List, the difference of linked lists:

List of lists (use index lookup, find the cost is small, insert is relatively slow),
Linked list (relatively slow to find, easy to insert),
The time spent will need to be weighed against specific usage situations.

3:queue, Stack differences

Queue (queues: FIFO queue)
Stack (stack: Advanced post-out)

4: Indexed access to the list

Index, also called subscript
Positive index: From left to right, starting with 0, numbering each element in a list
Negative index: From right to left, starting from-1
Positive and negative indexes cannot be indexerror or cause
Conventions: You can think of the list from left to right, the left is the head, the right is the tail, the left is the nether, the right is the upper bound

The list is accessed through the index. List[index],index is the index, using the brackets to access

5: Query method for list

Index (Value,[start,[stop]]) is found by value. If we don't find it, we'll throw valueerror, by the way of value traversal.
Finds whether an element within a list matches a specified range by value
The first match immediately returns the index, which is not matched and throws an exception valueerror
Count (value) traversal by value does not find that the value does not throw an exception. Returns the number of occurrences of the value in the list

The time complexity traversal looks for O (n), and the index and Count methods are O (n)

Len () The length method of the statistic list

6: How to Modify list elements

list[index]=value   索引不要超界

List Add, insert element

Append (object) Appends elements--->none list, returns None
Returning none means that no new list is generated and the list is modified directly. Time Complexity is O (1)
Insert (index,object)----->none Inserts an element at the specified index, object
Returning none means that no new list is generated and the list is modified directly. Time complexity is O (n)

Note (when using Insert ()): the upper bound is exceeded and the trailing is appended. Beyond the next, head append

Extend (iteratable)--->none appends the elements of an iterative object and returns none. Modify the list directly.
Time Complexity is O (1)

+----->list Creates a new object that is not referenced and is then garbage collected
Link operation, connect two lists, the original list will not change, will produce a new list
Essentially calling the--add_ () method

------>list Repeat, repeat the list element n times, put back the new list of duplicates, if the set sequence is also a series, you will encounter changes, and other duplicate elements are modified.

7: List of deleted elements
Remove (value)--->none to find the value of the first matching value from left to right, remove the element, and return None
Time complexity is O (n) and requires a lookup

Pop ([index])-->item
If index is not specified, an element is ejected from the tail of the list, in which case the time complexity is: O (1)
Specifies index, which pops an element from the index, and the index bounds throws a indexerror error

Clear ()---None clears all elements of the list, leaving an empty list

8: List of other actions
Reverse ()-->none reverse reverses the elements of the list and puts them back to None to modify the list directly.

Sort (key=none,reverse=false)-->none
Sorts the list elements, modifies the list directly, and the default ascending order. Reverse is true, reversed, descending
Key A function that specifies how key is sorted Lst.sort (key=functionname)

In to determine if a list belongs to another list

List summary in Python

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.