index(var)–error if abscent index(var, start, end)
remove(var)
pop() –returns, index optional
del list[index start : end]
max, min, sum,list.reverse(), sort() –for strings only sum will not work
map: ```python # input size of the list n = int(input(“Enter the size of list : “)) # store integrs in a list using map, # split and strip functions lst = list(map(int, input(“Enter the integer elements:”).strip().split()))[:n]
# printing the list print(‘The list is:’, lst)
```
Clear() Removes all items from the list
copy() Returns a copy of the list
Working:
Use array Data Structure (Array of references which are continous) . Actual items are not continous Dynamic insertion. Allocate extra memory
Preallocate some space. If becomes full
Allocate new space (multiply by x=1.125)
Copy old space to new
Free old space
Advantages:
Random Access (ith item in constant time, address computations done to find location of ith item)
Cache friendly
Dynamic size
Flexible types
DisAdvantages:
Insertion, Deletion and search are slow.Take linear time
Other functions
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.
Slicing
Negative steps to reverse list
gives different for list only. tuple gives same back…since immutable
Comprehensions
Sets
do not contain duplicates. {}
Sets
Dictionary
do not contain duplicates. {}
Comprehensions
list(li) to set, dictionay d1 = {x:x**3 for x in l1} d1 = {x:f”ID{x}” for x in l1} d1 = {l2[i]:l3[i] for i in range(len(l2))} or **## d3 = dict(zip(l2,l3)) **
reverse dictionary d2 = {v:k for (k,v) in d1.items()}
## A New Post for resources to learn Data Structures & Algorithms