【问题标题】:Generate multiple OR/AND statements [duplicate]生成多个 OR/AND 语句 [重复]
【发布时间】:2019-06-14 18:43:28
【问题描述】:

我正在研究基于文本中使用的关键字将文本拆分为不同块的 python 脚本。

目前我将文本分成这样的块(对于 1 个块,其他块的结构几乎相同):

       if (line.strip().lower().startswith('ключевые навыки') 
        or line.strip().lower().startswith('дополнительная информация') 
        or line.strip().lower().startswith('знания') 
        or line.strip().lower().startswith('личные качества') 
        or line.strip().lower().startswith('профессиональные навыки')
        or line.strip().lower().startswith('навыки')):

但是,关键字列表可能会扩大。是否有可能基于一些可能的关键字生成多个 or 语句?

【问题讨论】:

  • 不确定你想说什么/做什么。但看起来你应该先做keywords = ['kno4eBble', 'Aononhnt', ...],然后再做for keyword in keywords: if line.strip().lower().startswith(keyword):。或以上。
  • str.starts 以接受作为输入的项目元组,例如tup = ('a', 'b', 'c'); 'bar'.startswith(tup)

标签: python parsing text


【解决方案1】:

试试这个代码

values=['ключевые навыки','дополнительная информация','знания']
val=True
#enter any words you want to check
while val
    for i in values:
         if (line.strip().lower().startswith(i)):
              #whatever code you want to implement
              val=False
              #to exit loop

希望对你有帮助:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-01
    • 2021-05-13
    • 2014-08-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多