小编Mar*_*tit的帖子

Python:处理两个列表的"Pythonic"方法是什么?

说我在Python中有这个代码.我是Perl程序员,你可能会说.

# Both list1 and list2 are a list of strings
for x in list1:
  for y in list2:
    if y in x:
      return True
return False
Run Code Online (Sandbox Code Playgroud)

有什么更Pythonic的方法来处理这个问题?我认为列表理解可以做得很好,但我无法理解这个"过程两个单独的列表"的一部分.

python list-comprehension list

3
推荐指数
1
解决办法
146
查看次数

标签 统计

list ×1

list-comprehension ×1

python ×1