List Methods
Function | Description |
---|---|
Append() | Add an element to the end of the list |
Extend() | Add all elements of a list to another list |
Insert() | Insert an item at the defined index |
Remove() | Removes an item from the list |
Clear() | Removes all items from the list |
Index() | Returns the index of the first matched item |
Count() | Returns the count of the number of items passed as an argument |
Sort() | Sort items in a list in ascending order |
Reverse() | Reverse the order of items in the list |
copy() | Returns a copy of the list |
pop() | Removes and returns the item at the specified index. If no index is provided, it removes and returns the last item. |
To know more refer to this article – Python List methods
The operations mentioned above modify the list Itself.
Built-in functions with List
Function | Description |
---|---|
reduce() | apply a particular function passed in its argument to all of the list elements stores the intermediate result and only returns the final summation value |
sum() | Sums up the numbers in the list |
ord() | Returns an integer representing the Unicode code point of the given Unicode character |
cmp() | This function returns 1 if the first list is “greater” than the second list |
max() | return maximum element of a given list |
min() | return minimum element of a given list |
all() | Returns true if all element is true or if the list is empty |
any() | return true if any element of the list is true. if the list is empty, return false |
len() | Returns length of the list or size of the list |
enumerate() | Returns enumerate object of the list |
accumulate() | apply a particular function passed in its argument to all of the list elements returns a list containing the intermediate results |
filter() | tests if each element of a list is true or not |
map() | returns a list of the results after applying the given function to each item of a given iterable |
lambda() | This function can have any number of arguments but only one expression, which is evaluated and returned. |
Useful Links:
Python Lists
Python Lists are just like dynamically sized arrays, declared in other languages (vector in C++ and ArrayList in Java). In simple language, a list is a collection of things, enclosed in [ ] and separated by commas.