Machine Learning March 14, 2021 Python Comments Off on Python Lists 5,511 Views
Lists are used to store multiple items in a single variable. Lists are one of 4 built-in data types in Python used to store collections of data, the other 3 are Tuple, Set, and Dictionary, all with different qualities and usage.
Lists are created using square brackets: []
The del keyword also removes the specified index:
The del keyword can also delete the list completely.
So if you want a case-insensitive sort function, use str.lower as a key function:
using list comprehension
“Above is Return the item if it is not Mango, if it is Mango return Orange”.
You cannot copy a list simply by typing list2 = list1, because: list2 will only be a reference to list1, and changes made in list1 will automatically also be made in list2.
There are ways to make a copy, one way is to use the built-in List method copy().