(Self-developed artificial intelligence) pythony list, artificial intelligence pythony
How to Create a list:
A = [1, 2, 3, 4, 5]
In this way, the elements in the element enclosed by brackets are separated by commas. This form represents a list.
Common Operations in the list:
1. Element assignment:
A [0] = 10
Add a 10 value at the position where the index of the List is 0 and overwrite the original 1.
Result: a = [10, 2, 3, 4, 5]
2. Add the following elements:
A. append (6)
Here we use the append () method to add a new object at the end of the list.
Result: a = [,]
3. Delete elements:
Del a [0]
Here, we use del to delete the element whose index is 0.
Result: a = [2, 3, 4, 5, 6]
Common methods in the list:
1. append:
A. append (7) # Add a new object to the end of the list
2. count:
A. count (2) # count the number of times 2 appears in List
3. pop:
A. pop () # remove the last element from the list by default, and return the value of this element. a. pop (3) # Remove the element from the specified position and return the value of this element.
4. insert:
A. insert () # insert 10 at the position where the index value is 2. Add 1 to the element on the original index 2 and the element index after the index.
5. remove:
A. remove (10) # remove the first match from index 0
6. sort:
A. sort () # sort in ascending order by default
Use the reverse parameter:
A. sort (reverse = True) # sort in reverse order
The string can use key = len:
A. sore (key = len) # sort by string from short to long a. sore (key = len, reverse = True) # sort by string from long to short