How to filter a dictionary ?
Nikhil Verma
varma.nikhil22 at gmail.com
Tue Apr 10 01:49:41 EDT 2012
HI All
I want to filter a dictionary on the basis of its values.
for_patient_type = {37: u'Test', 79: u'Real', 80: u'Real', 81: u'Real', 83:
u'Real', 84: u'Real', 91: u'Real', 93: u'Real'}
I want if the values are 'Real' give me the keys that have values 'Real'
like this.
{79:'Real'}
{80:'Real'}
{81:'Real'}
{83:'Real'}
{84:'Real'}
{91:'Real'}
{93:'Real'}
I am trying this but its giving me a generator object.
In [9]: (k for k,v in for_patient_type.iteritems() if v == 'Real')
Out[9]: <generator object <genexpr> at 0x32ddc80>
Thanks in advance
--
Regards
Nikhil Verma
+91-958-273-3156
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20120410/76fab6ae/attachment.html>
More information about the Python-list
mailing list