tags:

views:

87

answers:

1

I'm trying to create an array of all .asm files I need to build except for one that is causing me trouble right now. Here's what I have, based on the Scons "Handling Common Cases" page:

projfiles['buildasm'] = 
  ['#build/'+os.path.splitext(x)[0]+'.asm' for x in projfiles['a']];

(this maps paths of the form 'foo.a' to '#build/foo.asm')

I want to run this for each member of projfiles['a'] except if a member of the array matches 'baz.a'. How can I do this?

+7  A: 
projfiles['buildasm'] = ['#build/'+os.path.splitext(x)[0]+'.asm' for x in projfiles['a'] if x != 'baz.a']

or more generally:

ignored_files = ['baz.a',
                 'foo.a',
                 'xyzzy.a',
                 ]
projfiles['buildasm'] = ['#build/'+os.path.splitext(x)[0]+'.asm' for x in projfiles['a'] if x not in ignored_files]
Kristopher Johnson
thanks... most of Python's syntax is new to me. If ignored_files is a large list, is it better to use a dictionary lookup rather than an array?
Jason S
Its best to use a set() then.
bayer