On Wed, Sep 1, 2010 at 12:27 AM, Alban Nona <python.k...@gmail.com> wrote:
> Hi all, > > Im stuck on this problem: > I have a function which return me a list of string (basically the result > looks like: ["FN067_098_MEN", FN067_098_JIN", FN067_098_BG"] > In other hand, I have another list full of that kind of entries: > > ["FN067_098_MEN_Hair_PUZ_v001.0001.exr","FN067_098_JIN_Hair_SPC_v001.0001.exr","FN067_098_MEN_Jin_MVE_v001.0001.exr","FR043_010_GEN_NRM_v001.0001.exr"] > > I would like to do something like this: > > myFirstList = ["FN067_098_MEN", FN067_098_JIN", FN067_098_BG"] > mySecondList = > ["FN067_098_MEN_Hair_PUZ_v001.0001.exr","FN067_098_JIN_Hair_SPC_v001.0001.exr","FN067_098_MEN_Jin_MVE_v001.0001.exr","FR043_010_GEN_NRM_v001.0001.exr"] > > for n in myFirstList: > if n in mySecondList: > mySecondList.remove(n) > > In fact, what I want to do it to remove entries with the secondlist which > content the entries of the first one. But it seems to not work like this. > Someone can help me please ? did I miss something ? > You can try this if you don't care about the order. >>> myFirstList = ["FN067_098_MEN", "FN067_098_JIN", "FN067_098_BG"] >>> mySecondList = ["FN067_098_MEN_Hair_PUZ_v001.0001.exr","FN067_098_JIN_Hair_SPC_v001.0001.exr","FN067_098_MEN_Jin_MVE_v001.0001.exr","FR043_010_GEN_NRM_v001.0001.exr"] >>> list(set(mySecondList).difference(myFirstList)) ['FN067_098_MEN_Jin_MVE_v001.0001.exr', 'FN067_098_MEN_Hair_PUZ_v001.0001.exr', 'FR043_010_GEN_NRM_v001.0001.exr', 'FN067_098_JIN_Hair_SPC_v001.0001.exr'] Another example to make this clear. >>> a = range(10) >>> b = range(5,15) >>> a [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> b [5, 6, 7, 8, 9, 10, 11, 12, 13, 14] >>> list(set(b).difference(a)) [10, 11, 12, 13, 14] -- ~l0nwlf
-- http://mail.python.org/mailman/listinfo/python-list