我想动态更改列表中的值。
现在,我有:
sectors = ['MSCI ACWI/CONSUMER DISCR', 'MSCI ACWI/CONSUMER STAPLES', 'MSCI ACWI/ENERGY', 'MSCI ACWI/FINANCIALS', 'MSCI ACWI/HEALTH CARE', 'MSCI ACWI/INDUSTRIALS', 'MSCI ACWI/INFORMATION TECH', 'MSCI ACWI/MATERIALS', 'MSCI ACWI/METALS & MINING', 'MSCI ACWI/TELECOM SVC','MSCI ACWI/UTILITIES']
regions = ['MSCI NORTH AMERICA', 'MSCI EUROPE', 'MSCI PACIFIC', 'MSCI EM LATIN AMERICA', 'MSCI EM EUROPE', 'MSCI EM ASIA']
现在,我想创建一个从regions
和sectors
派生的新列表,这样我就有了类似的东西:
regions_CONSUMER DISCR = ['MSCI NORTH AMERICA/CONSUMER DISCR', 'MSCI EUROPE/CONSUMER DISCR', 'MSCI PACIFIC/CONSUMER DISCR', 'MSCI EM LATIN AMERICA/CONSUMER DISCR', 'MSCI EM EUROPE/CONSUMER DISCR', 'MSCI EM ASIA/CONSUMER DISCR']
regions_CONSUMER STAPLES = ['MSCI NORTH AMERICA/CONSUMER STAPLES', 'MSCI EUROPE/CONSUMER STAPLES', 'MSCI PACIFIC/CONSUMER STAPLES', 'MSCI EM LATIN AMERICA/CONSUMER STAPLES', 'MSCI EM EUROPE/CONSUMER STAPLES', 'MSCI EM ASIA/CONSUMER STAPLES']
我该如何实现?
答案 0 :(得分:1)
尝试一下-
regions_CONSUMER_DISCR = [x+'/CONSUMER DISCR' for x in regions]
regions_CONSUMER_STAPLES = [x+'/CONSUMER STAPLES' for x in regions]