List Methods
eharetea

Basic operations for lists.

Lists in Python.

Date Created:Friday December 29th, 2006 03:41 AM
Date Modified:Friday August 01st, 2008 01:28 AM

len(L)
L.append(x)
L.extend([2,3,4])
L.sort()
L.index(1)
L.reverse()
del L[k]
del L[i:j]
L.pop()
L[i:j]=[4,5,6]
L[:-2]


>>> S = 'Hello World!'
>>> L = list(S)
>>> L
['H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd', '!']
>>> len(L)
12
>>> L.pop()
'!'
>>> L = L[0:]
>>> L
['H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd']
>>> L[1:] = [3]
>>> L
['H', 3]
>>> L[1:] = ['e','l','l','o','!']    
>>> L
['H', 'e', 'l', 'l', 'o', '!']
>>> 


>>> odforce.send_data('ls')
()
>>> new=odforce.get_data()
>>> new
'geo1\ngeo2\ngeo3\ngeo4'
>>> new.split('\n')
['geo1', 'geo2', 'geo3', 'geo4']