Python 仅从列表中获取所需字符串

Python 仅从列表中获取所需字符串,python,string,list,Python,String,List,假设我有如下清单 list_fields = ['Full-Time', 'Options:', 'Express your interest', 'Email this to a friend', 'More information about this job:', 'Overview:', 'A', 'Parasite', 'position is cool', 'Are you a LEADER?', 'For sure there', 'Hello doing?'

假设我有如下清单

list_fields = ['Full-Time',
 'Options:',
 'Express your interest',
 'Email this to a friend',
 'More information about this job:',
 'Overview:',
 'A',
 'Parasite',
 'position is cool',
 'Are you a LEADER?',
 'For sure there',
 'Hello doing?',
 'If so you will EXCEL.',
 'Bring your skills',
 'programs and procedures']
我试图做的是收集
概述
之后的所有字符串,我的意思是需要忽略
概述
字符串之前的字符串。在
概述
之前和之后可能有许多字符串,但只想将
概述
之后的所有字符串收集为一个列表,并希望使用类似
''的方法将它们作为单个字符串。join([list_fields])
对不起,如果我一次又一次地使用单词,谁能告诉我怎么做

Edited Code:
  • 我们只能从“概述”之后到“展示您的技能”之前获取

  • 提前感谢

    如果您知道字符串通常是概述:,您可以这样做

    ''.join(list_fields[list_fields.index("Overview:") + 1:])
    
    这将使用
    list.index()
    确定列表中
    概述:
    的索引,并使用切片从
    概述:
    之后的索引开始获取子列表

    因此,在您的情况下,您可以:

    "".join(list_fields[list_fields.index("Overview:"):])
    
    回答评论中的问题:

    def my_slice(l,a,b):
        try:
            a_idx = l.index(a)
            b_idx = l.index(b)
    
        except ValueError:
            return []
    
        if a_idx > b_idx:
            a_idx, b_idx = b_idx, a_idx
        return l[a_idx:b_idx+1]
    
    my_slice(list_fields,'Overview:','Bring your skills')
    

    切片应该与索引一起工作。如果未找到,则不会处理该错误

    lstResults = list_fields[list_fields.index('overview'):]
    

    这是最好的解决方案,因为你不知道文本是什么。我认为@Sven Marnach的解决方案是正确的。但我宁愿先将列表“连接”到字符串中,然后再进行搜索。一个优点是——如果您要查找的字符串不在其中,那么它将以空字符串结束。一个缺点是,它无法区分字符串是键还是键的一部分。因此,我想解决方案取决于您的问题上下文。@dolaameng它甚至可能是两个键通过一些小机会连接在一起。实际上,字符串概述:是fiexed,它将在那里sure@jamylak:是的,它可能发生。但是考虑到列表中的元素实际上是单词,我认为这甚至可能是一件好事——例如,对于文本处理任务,单词“overview”可能会被一个新行或空格意外地分隔开。如果它是一个文本垃圾文本,我不认为使用“单词”作为探针是一个好主意。:)但是这里的概述:字符串是硬核心的,它将确保您在“概述”之前而不是之后收集项目。如果我们只想从2到6收集项目,那是[2,3,4,5,6]不,实际上我必须通过单词本身来查找,因为如果列表中的某些单词最终增加,索引将正确更改,如果你知道哪个是索引(2在6之前)然后:
    a[a.index(2):a.index(6)+1]
    你可以试试这个:
    b=a[a.index(2):a.index(6)+1]
    如果不是b:b=a[a.index(6):a.index(2)+1]
    import itertools as it
    
    list(it.dropwhile(lambda x: not x.lower().startswith('overview'), list_fields))[1:]
    
    lstResults = list_fields[list_fields.index('overview'):]