Built-in List Functions & Methods:
Python includes the following list functions −
SN Function with Description
1
cmp(list1, list2)
Compares elements of both lists.
2 len(list)
Gives the total length of the list.
3
max(list)
Returns item from the list with max value.
4 min(list)
Returns item from the list with min value.
5
list(seq)
Converts a tuple into list.
Python includes following list methods
SN Methods with Description
1
list.append(obj)
Appends object obj to list
2 list.count(obj)
Returns count of how many times obj occurs in list
3
list.extend(seq)
Appends the contents of seq to list
4 list.index(obj)
Returns the lowest index in list that obj appears
5
list.insert(index, obj)
Inserts object obj into list at offset index
6 list.pop(obj=list[-1])
Removes and returns last object or obj from list
7
list.remove(obj)
Removes object obj from list
8 list.reverse()
Reverses objects of list in place
9
list.sort([func])
Sorts objects of list, use compare func if given
Built-in Tuple Functions
Python includes the following tuple functions −
SN Function with Description
1
cmp(tuple1, tuple2)
Compares elements of both tuples.
2 len(tuple)
Gives the total length of the tuple.
3
max(tuple)
Returns item from the tuple with max value.
4 min(tuple)
Returns item from the tuple with min value.
5
tuple(seq)
Converts a list into tuple.
Built-in Dictionary Functions & Methods −
Python includes the following dictionary functions −
SN Function with Description
1
cmp(dict1, dict2)
Compares elements of both dict.
2 len(dict)
Gives the total length of the dictionary. This would be equal to the number of items in the
dictionary.
3
str(dict)
Produces a printable string representation of a dictionary
4 type(variable)
Returns the type of the passed variable. If passed variable is dictionary, then it would return
a dictionary type.
Python includes following dictionary methods −
SN Methods with Description
1 dict.clear()
Removes all elements of dictionary dict
2
dict.copy()
Returns a shallow copy of dictionary dict
3
dict.fromkeys()
Create a new dictionary with keys from seq and values set to value.
4 dict.get(key, default=None)
For key key, returns value or default if key not in dictionary
5
dict.has_key(key)
Returns true if key in dictionary dict, false otherwise
6 dict.items()
Returns a list of dict's (key, value) tuple pairs
7
dict.keys()
Returns list of dictionary dict's keys
8 dict.setdefault(key, default=None)
Similar to get(), but will set dict[key]=default if key is not already in dict
9
dict.update(dict2)
Adds dictionary dict2's key-values pairs to dict
10 dict.values()
Returns list of dictionary dict's values