>>> data = "" 0, 'title': 'Linux'}, {'id': 1, 'title': 'FreeBSD'})
>>> id = 0
>>> result = [x for x in data if x['id'] == id]
[{'id': 0, 'title': 'Linux'}]
>>> result = [x for x in data if x['id'] == id]
>>> result[0]
{'id': 0, 'title': 'Linux'}
>>>
You get the entire dict entry out of the tuple that way.
On 11/9/06, Basil Shubin <[EMAIL PROTECTED]> wrote:
Hi friends!
Imagine the tuple that has dictionaries as it's item:
>>> print data
({'id': 0, 'title': 'Linux'}, {'id': 1, 'title': 'FreeBSD'})
How I can get index of tuple item where dict's key 'id' equal to
appropriate value? And can this be done without 'for' loops, just in one
string?
--
Basil Shubin
Freelance Software Developer
_______________________________________________
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor