我在列表中有一个列表,我想删除某些元素,然后再遇到其中一个元素的值。下面给出示例:
输入:
A = [[abc], [qwe], [zxc], [asd], [name, qwe, qqwe,pos],[qwerty,lkasd, banner, kostop]] ...
输出:
Output = [[name, qwe,qqwe,pos], [qwerty,lkasd, banner, kostop]] …
应该删除包含“名称”的元素之前的所有元素。
我不知道这是否算作虐待动物...
>>> a = [['abc'], ['qwe'], ['zxc'], ['asd'], ['name', 'qwe', 'qqwe', 'pos'], ['qwerty', 'lkasd', 'banner', 'kostop']]
>>> from itertools import dropwhile
>>> list(dropwhile(lambda x: 'name' not in x, a))
[['name', 'qwe', 'qqwe', 'pos'], ['qwerty', 'lkasd', 'banner', 'kostop']]