特定のアイテムが表示された後にすべてのアイテムを表示するようにリストをフィルタリングするために、この関数を作成しました。組み込みの文字列メソッドにやや似ていますstr.rpartition(sep)。おそらくリスト内包表記を使用して、これを行うためのよりコンパクトな方法があると感じています。何か案は?
def ignore_until(the_list, match):
    # Ignore all items in the_list prior to match
    found = False
    for index, item in enumerate(the_list):
        if item == match:
            found = True
            break
    if found:
        return the_list[index:]
    else:
        return []
my_list = ['red','orange','yellow','green']
assert ignore_until(my_list, 'yellow') == ['yellow','green']
assert ignore_until(my_list, 'blue') == []
編集:
上記の質問に対する回答を見た後、6 つの回答のうち 5 つがindex()リスト データ型の組み込みメソッドに焦点を当てていることに気付きました。実際、私は正規表現を使用する必要があり、質問からそれを省略すると人々の回答に影響を与えることに気づきませんでした。正規表現コードは次のとおりです。
import re
def ignore_until(the_list, pattern):
    # Ignore all items in the_list prior to the item containing pattern.
    found = False
    for index, item in enumerate(the_list):
        if re.search(string=item, pattern=pattern):
            found = True
            break
    if found:
        return the_list[index:]
    else:
        return []
my_list = ['red','orange','yellow','green']
assert ignore_until(my_list, 'yellow') == ['yellow','green']
assert ignore_until(my_list, 'blue') == []