retrieving from list
Marc Tardif
intmktg at Gloria.CAM.ORG
Mon May 29 16:16:09 EDT 2000
If I have a multi-level list in a function, how can I pass some argument
to the function in order to retrieve a specific member of the list? For
example, supposing I have:
def func(arg):
a = []
a.append('foo')
b = []
b.append('bar')
a.append(b)
# now I have a = ['foo', ['bar']]
return a[arg][arg]
The last line is where the problem lies. How can 'arg' be able to refer to
'foo' or 'bar'? Should 'arg' be a string of comma seperated values which
would be parsed within the function in order to refer to the proper member
of the list? For example, '0' for 'foo' and '0,0' for 'bar'?
Any ideas to solve this little problem would be much appreciated,
Marc
More information about the Python-list
mailing list