Py学习  »  David Remus  »  全部回复
回复总数  1
5 年前
回复了 David Remus 创建的主题 » 错误:带有regex的Python脚本中的错误转义

如果我理解正确,这里不需要regex。

group_1 = ['brasil','argentina','chile','canada']
group_2 = ['brasil.sao_paulo','chile','argentina']

for x in group_1:
    # For group 2 only, this picks out the part of the string that appears before the first ".".
  if x in [y.split('.')[0] for y in group_2]:
    print("Match: {}".format(x))
  else:
    print("Not match: {}".format(x))

又回来了

Match: brasil
Match: argentina
Match: chile
Not match: canada