Python 列表过滤删除太多

Python List Filtering Removes Too Many

I python 字符串形式的 url 列表。我正在尝试删除所有包含两个正斜杠 (//) 的字符串。这是我尝试这样做的方式:

filtered_list = [x for x in original_list if 'https://www.ourlads.com/ncaa-football-depth-charts/player//' not in x]

但是,当我 运行 这样做时,它会删除所有带有 // 的字符串以及甚至不包含 // 的其他字符串。

这是原始列​​表的示例:

original_list = ['https://www.ourlads.com/ncaa-football-depth-charts/player/devonta-smith/123433',
'https://www.ourlads.com/ncaa-football-depth-charts/player//0',
'https://www.ourlads.com/ncaa-football-depth-charts/player//116922',
'https://www.ourlads.com/ncaa-football-depth-charts/player/alex-leatherwood/123411']

我可以更改什么以便它只删除其中包含 // 的字符串?

您的代码似乎可以正常工作。 但另一种方法是通过正则表达式。

import re

original_list = ['https://www.ourlads.com/ncaa-football-depth-charts/player/devonta-smith/123433',
'https://www.ourlads.com/ncaa-football-depth-charts/player//0',
'https://www.ourlads.com/ncaa-football-depth-charts/player//116922',
'https://www.ourlads.com/ncaa-football-depth-charts/player/alex-leatherwood/123411']

filtered_list = [x for x in original_list if not re.match(r"^https://.*//", x)]
filtered_list

filter_list:

['https://www.ourlads.com/ncaa-football-depth-charts/player/devonta-smith/123433',
 'https://www.ourlads.com/ncaa-football-depth-charts/player/alex-leatherwood/123411']