【问题标题】:String check with list of strings [duplicate]使用字符串列表检查字符串 [重复]
【发布时间】:2018-06-03 06:36:09
【问题描述】:

确保以下内容可信的最快方法是什么:

email = "foobar@gmail.com"

trusted = [".co.uk", ".com", ".net", ".edu", ".ac.uk"]

【问题讨论】:

  • 可信的,解释清楚
  • 你的意思是if any(email.endswith(s) for s in trusted) 吗?
  • 字符串中的endswith()方法

标签: python


【解决方案1】:

您可以对这些事情使用过滤器:

list(filter(lambda x: email.endswith(x),trusted))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-11-17
    • 2013-01-09
    • 2017-05-31
    • 2015-05-05
    • 2015-01-22
    • 2019-05-24
    • 2018-11-28
    • 2023-03-31
    相关资源
    最近更新 更多