1.测试文章
~~~~~~~~~~~~~~~~~~~~
1 #例:找到嵌套列表中名字含有两个‘e’的所有名字 2 names = [[‘Tom‘, ‘Billy‘, ‘Jefferson‘, ‘Andrew‘, ‘Wesley‘, ‘Steven‘, ‘Joe‘], 3 [‘Alice‘, ‘Jill‘, ‘Ana‘, ‘Wendy‘, ‘Jennifer‘, ‘Sherry‘, ‘Eva‘]] 4 5 print([name for lst in names for name in lst if name.count(‘e‘) >= 2]) # 注意遍历顺序,这是实现的关键
#例:找到嵌套列表中名字含有两个‘e’的所有名字 names = [[‘Tom‘, ‘Billy‘, ‘Jefferson‘, ‘Andrew‘, ‘Wesley‘, ‘Steven‘, ‘Joe‘], [‘Alice‘, ‘Jill‘, ‘Ana‘, ‘Wendy‘, ‘Jennifer‘, ‘Sherry‘, ‘Eva‘]] print([name for lst in names for name in lst if name.count(‘e‘) >= 2]) # 注意遍历顺序,这是实现的关键