actual_file_names = ['', 'python', 'cmdb_dma_map.json', 'mappings.json', 'vendor_provided_binaries.json',
'vendor_provided_binaries_custom.json', 'DMAPremiumDatabase10.50.000.000.jar',
'DMAPremiumMiddleware10.50.000.000.jar', 'DMAPremiumUtilities10.50.000.000.jar',
'dma_oo_client_bin_linux.zip', 'dma_oo_client_bin_linux.zip.MD5', 'dma_oo_client_code_linux.zip',
'dma_oo_client_code_linux.zip.MD5', 'DCAFlowUtilities1.0.0.0.jar', 'DCAKafkaWriter1.0.0.0.jar',
'DCAUtilities1.0.0.0.jar']
expected_file_names = ['python', 'cmdb_dma_map.json', 'mappings.json', 'vendor_provided_binaries.json',
'vendor_provided_binaries_custom.json', 'DMAPremiumDatabase.jar', 'DMAPremiumMiddleware.jar',
'DMAPremiumUtilities.jar']
# 1'st way
print [str(afn)+" is valid" if any(efn.split(".")[0] in afn for efn in expected_file_names) else str(afn)+"N/A" for afn in actual_file_names]
# 2'nd way
for efn in expected_file_names:
for afn in actual_file_names:
if efn.split(".")[0] in afn:
print afn
输出:
['N/A', 'python is valid', 'cmdb_dma_map.json is valid', 'mappings.json is valid', 'vendor_provided_binaries.json is valid', 'vendor_provided_binaries_custom.json is valid', 'DMAPremiumDatabase10.50.000.000.jar is valid', 'DMAPremiumMiddleware10.50.000.000.jar is valid', 'DMAPremiumUtilities10.50.000.000.jar is valid', 'dma_oo_client_bin_linux.zipN/A', 'dma_oo_client_bin_linux.zip.MD5N/A', 'dma_oo_client_code_linux.zipN/A', 'dma_oo_client_code_linux.zip.MD5N/A', 'DCAFlowUtilities1.0.0.0.jarN/A', 'DCAKafkaWriter1.0.0.0.jarN/A', 'DCAUtilities1.0.0.0.jarN/A']
python
cmdb_dma_map.json
mappings.json
vendor_provided_binaries.json
vendor_provided_binaries_custom.json
vendor_provided_binaries_custom.json
DMAPremiumDatabase10.50.000.000.jar
DMAPremiumMiddleware10.50.000.000.jar
DMAPremiumUtilities10.50.000.000.jar