def test():
s = ['desc_recommend_splitable_container_seeMore_17', 'itemInfo_641049504158', 'desc_recommend_splitable_container_seeMore_15', 'itemInfo_630548745584']
# 我要怎么才能拿到包含itemInfo的所有值
# 我不太会写正则
# 或者用if语句取
if __name__ == '__main__':
test()
确实不需要正则表达式:
def test():
s = ['desc_recommend_splitable_container_seeMore_17', 'itemInfo_641049504158', 'desc_recommend_splitable_container_seeMore_15', 'itemInfo_630548745584']
infos = list(filter(lambda str_: 'itemInfo' in str_, s))
print(infos)
if __name__ == '__main__':
test()
filter 函数接受一个函数和一个可迭代对象,这个函数的返回值指示是否要保留某个元素。
你要取哪些值?