我想在一个充满字符串的列表中找到一个特定的条目。例如,我想找到所有包含数字“ .0130”的字符串。 (如下面的第三行)
文件如下:
https://ladsweb.modaps.eosdis.nasa.gov/archive/allData/6/MYD021KM/2018/001/MYD021KM.A2018001.0140.006.2018002030901.hdf
https://ladsweb.modaps.eosdis.nasa.gov/archive/allData/6/MYD021KM/2018/001/MYD021KM.A2018001.0135.006.2018002030858.hdf
https://ladsweb.modaps.eosdis.nasa.gov/archive/allData/6/MYD021KM/2018/001/MYD021KM.A2018001.0130.006.2018002030850.hdf
https://ladsweb.modaps.eosdis.nasa.gov/archive/allData/6/MYD021KM/2018/001/MYD021KM.A2018001.0125.006.2018002030903.hdf
我这样读取文件:
data_links = []
f=open(workdir1+"/download.txt", "r")
for i in f:
data_links.append(i.rstrip())
f.close()
我如何查找包含“ .0130”部分的所有条目?
答案 0 :(得分:2)
my_list = [line for line in file if ".0130" in line]
答案 1 :(得分:0)
也可以使用正则表达式
import re
[i for i in your_list if(re.search('\.0130\.',i) is not None)]