simple way to un-nest (flatten?) list

djc anrnsrisnotreqid at blueyonder.co.uk
Sun Nov 5 16:43:33 EST 2006


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')



-- 
djc



More information about the Python-list mailing list