On Fri, 30 Jan 2009 14:23:31 -0800
Matthew Sacks <ntw...@gmail.com> wrote:
> let me re-phrase that question:
> i would like to access the element of individual tuples inside of a
> list, by using an index.
> so i have the list contents
> 
> print list
> [('--datasourcename', 'DB'), ('--password', '123')]
> 
> How can I access "DB" from the list directly using an index?

First of all, list is a reserved word.  Don't use it as a variable name.

mylist[0][1] if I understand the question.

I don't know what you are trying to accomplish but is this snippet
useful?

opts = dict([(x[0][2:], x[1]) for x in mylist if x[0][:2] == '--'])
print opts['datasourcename']

-- 
D'Arcy J.M. Cain <da...@druid.net>         |  Democracy is three wolves
http://www.druid.net/darcy/                |  and a sheep voting on
+1 416 425 1212     (DoD#0082)    (eNTP)   |  what's for dinner.
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to