内联循环Python。检查列表中的每个成员是否为内联的另一个列表

时间:2014-01-25 03:59:55

标签: python list-comprehension

我有一个问题,我一直想要问一段时间。我有一些代码,我试图检查引用列表中的每个项目到另一个列表,所有这些INLINE。例如:

if int(word[:-1])>=1 and int(word[:-1])<=31 and for word in LIST1, word in LIST2:
                day = word[:-1]

更具体地说,这是数据抓取程序的一部分,用于过滤掉日期和月份等各种数据字段。

months = ["January","February",etc......]
days = ["monday,","tuesday,","wednesday,","thursday,","friday,","saturday,","sunday,"]
if word.lower() in days and For i in line.split(), months.contains(i)

例如,在list1中我每周都有。如果LIST2包含一周中的任何(不是全部)天,则评估为真。有谁知道这样做的光滑方式?谢谢。

1 个答案:

答案 0 :(得分:3)

if set(list2) & set(list1):
   print "there is something in list2 that matches something in list1"

print "The days in list2 are", set(list2) & set(list1)