How to manipulate list of dictionary
Simon Brunning
simon at brunningonline.net
Tue Aug 26 04:29:27 EDT 2008
2008/8/26 ajak_yahoo <arazak73 at yahoo.com.my>:
> Need some help, I have a list of dictionary as below,
>
> table = [{"Part #":"Washer","Po #":"AE00128","qty":100},
> {"Part #":"Brake Pad","Po #":"AE00154","qty":150},
> {"Part #":"Mesh","Po #":"AE00025","qty":320},
> {"Part #":"Mouse","Po #":"AE00207","qty":120},
> {"Part #":"Insulator","Po #":"AE0013","qty":190}]
>
> How to manipulate the table?
>
> I need to search for the Po #, and display the result as below.
>
>
> Part # : Mouse
> Po # : AE00207
> Qty : 120 pcs
Well, that's a really bad data structure for what you want to do, but
you can do it with something like (untested):
wanted = 'AE00207'
for part in table:
if part['Po #'] == wanted:
print "Part #:\t%(Part #)s\nPo #:\t%(Po #)s\nQty #:\t%(qty)s" % part
--
Cheers,
Simon B.
simon at brunningonline.net
http://www.brunningonline.net/simon/blog/
GTalk: simon.brunning | MSN: small_values | Yahoo: smallvalues | Twitter: brunns
More information about the Python-list
mailing list