modifying a list element from a function

Kent kent.yuan at gmail.com
Fri Mar 27 12:00:26 CET 2009


> * to do the same modification on the list "a" within a function
> * not to hardcode in this function the position of the string in each


>>> a = [ [4, "toto"], [5, "cou"] ]
>>> def assign(element,pos,newValue):
...     element[pos]=newValue
...
>>> assign(a[0],1,'xxx')
>>> print a
[[4, 'xxx'], [5, 'cou']]
>>>

does it fit the requirement?



More information about the Python-list mailing list