Other list operations

Here are some of the other list operations we frequently use in Python.

  • count - number of time an element is present in a list.

  • sort - to sort the data with in the list. Data in the list will be sorted in-place.

s ='asdfasfsafljojlsdfaljfasf'
l = list(s)
l.count?
Docstring: L.count(value) -> integer -- return number of occurrences of value
Type:      builtin_function_or_method
l.count('a')
5
l.count('z')
0
l.sort?
Docstring: L.sort(key=None, reverse=False) -> None -- stable sort *IN PLACE*
Type:      builtin_function_or_method
l.sort()
l
['a',
 'a',
 'a',
 'a',
 'a',
 'd',
 'd',
 'f',
 'f',
 'f',
 'f',
 'f',
 'f',
 'j',
 'j',
 'j',
 'l',
 'l',
 'l',
 'o',
 's',
 's',
 's',
 's',
 's']
l.reverse?
Docstring: L.reverse() -- reverse *IN PLACE*
Type:      builtin_function_or_method
l.reverse()
l
['s',
 's',
 's',
 's',
 's',
 'o',
 'l',
 'l',
 'l',
 'j',
 'j',
 'j',
 'f',
 'f',
 'f',
 'f',
 'f',
 'f',
 'd',
 'd',
 'a',
 'a',
 'a',
 'a',
 'a']