djc wrote: > There is I am sure an easy way to do this, but I seem to be brain dead > tonight. So: > > I have a table such that I can do > > [line for line in table if line[7]=='JDOC'] > and > [line for line in table if line[7]=='Aslib'] > and > [line for line in table if line[7]=='ASLIB'] > etc > > I also have a dictionary > r= {'a':('ASLIB','Aslib'),'j':('JDOC', 'jdoc')} > so I can extract values > r.values() > [('ASLIB', 'Aslib'), ('JDOC', 'jdoc')] > > I would like to do > > [line for line in table if line[7] in ('JDOC','jdoc','Aslib','ASLIB')] > > so how should I get from > {'a':('ASLIB','Aslib'),'j':('JDOC','jdoc')} > to > ('Aslib','ASLIB','JDOC','jdoc')
Meet itertools: from itertools import chain names = set(chain(*r.itervalues())) print [line for line in table if line[7] in names] George -- http://mail.python.org/mailman/listinfo/python-list