Python 创建和填充具有可变数据量的口述录
考虑以下数据结构:Python 创建和填充具有可变数据量的口述录,python,python-2.7,dictionary,optimization,creation,Python,Python 2.7,Dictionary,Optimization,Creation,考虑以下数据结构: #Each key in this dict will only house 1 file [will have any number of keys] Predictor_dict = {'pred1':pred1.file,'pred2':pred2.file,...} #Each key in start_dict will house 1 OR 2 files start_dict={'start1.file':[s1m.file,s2m.file]} OR sta
#Each key in this dict will only house 1 file [will have any number of keys]
Predictor_dict = {'pred1':pred1.file,'pred2':pred2.file,...}
#Each key in start_dict will house 1 OR 2 files
start_dict={'start1.file':[s1m.file,s2m.file]} OR start_dict={'start1.file':s1m.file}
#Each key in start_end will house 1 OR 2 files
end_dict={'end1.file':[e1m.file,e2m.file]} OR end_dict={'end1.file':e1m.file}
现在,我有以下情况:
- 对于每个预测器,都有一个开始和结束
- 对于每个预测器,有两个可能的开始文件和一个结束文件
- 对于每个预测器,都有一个开始文件和两个结束文件
- 对于每个预测器,有2个可能的开始文件和2个可能的结束文件
file_picker={'pred1':[start1.file,s1m.file,end1.file,e1m.file,pred1.file]}
对于每个预测器,有2个可能的开始文件和2个可能的结束文件
# This will get the first start and end
file_picker={'pred1':[start1.file,s1m.file,end1.file,e1m.file,pred1.file]}
# This will house the first start and second end
file_picker_multiple_e={'pred1':[start1.file,s1m.file,end1.file,e2m.file,pred1.file]}
#This will house the second start, but first end
file_picker_multiple_s={'pred1':[start1.file,s2m.file,end1.file,e1m.file,pred1.file]}
#This will house second end and second start
file_picker_multiple_e_s={'pred1':[start1.file,s2m.file,end1.file,e2m.file,pred1.file]}
我认为让它创建4个字典,只返回案例需要的字典,比制作一个大字典更干净、更好
我目前拥有的psuedo代码示例(似乎有点太暴力了)
尽管我已经做到了一定程度,但我想看看是否有更好更快的方法来实现这一点
# function dict_maker will make a dictionary such as:
def dict_maker(start_landsat,start_modis,end_landsat,end_modis,pred):
made_dict={}
made_dict[pred]=[start_landsat,start_modis,end_landsat,end_modis,pred]
#where all the arguments are recieved from another function which takes a look at each of the start and end dictionaries as described above..