如何在Python中查找或删除列表中的子串列表
mylist = ['abc123', 'def456', 'ghi789','ghi123']sub = ['123','456']new_list = []先确定正常的写法for my_str in mylist:for sub_str in sub:
if sub_str in my_str:
new_list.append(my_str)print new_list然后在理解这颗语法糖print [j for i in range(5) for j in range(i)]最后改写下print [my_str for my_str in mylist for sub_str in sub if sub_str in my_str]
赞0
踩0