[Solved] Split list of lists in new list [closed]


You may simply map the split, filter if it makes a size 2 tuple, and zip it to get the values separately:

In[9]: l=['Name', 'AMAZON.COM - TOT RETURN IND', 'AMAZON.COM INC - NET CASH FLOW - FINANCING', 'AMAZON.COM INC - NET CASH FLOW - INVESTING', 'AMAZON.COM INC - NET CASH FLOW-OPERATING ACTIVS', 'AMAZON.COM INC - COST OF GOODS SOLD (EXCL DEP)', 'AMAZON.COM INC - EARNINGS BEF INTEREST & TAXES', 'AMAZON.COM INC - EBIT & DEPRECIATION', 'AMAZON.COM INC - GROSS INCOME', 'AMAZON.COM INC - NET SALES OR REVENUES', 'AMAZON.COM INC - OPERATING INCOME', 'AMAZON.COM INC - NET INCOME AVAILABLE TO COMMON', 'AMAZON.COM INC - ACCOUNTS PAYABLE', 'AMAZON.COM INC - CASH', "AMAZON.COM INC - COMMON SHAREHOLDERS' EQUITY", 'AMAZON.COM INC - CURRENT ASSETS - TOTAL', 'AMAZON.COM INC - CURRENT LIABILITIES-TOTAL', 'AMAZON.COM INC - TOTAL INVENTORIES', 'AMAZON.COM INC - LONG TERM DEBT', 'AMAZON.COM INC - TOTAL ASSETS']

In[22]: companies, ratios =zip(*filter( lambda y: len(y) == 2, map(lambda x: tuple(x.split(" - ")), l)))
In[23]: companies
Out[22]: 
('AMAZON.COM',
 'AMAZON.COM INC',
 'AMAZON.COM INC',
 'AMAZON.COM INC',
 'AMAZON.COM INC',
 'AMAZON.COM INC',
 'AMAZON.COM INC',
 'AMAZON.COM INC',
 'AMAZON.COM INC',
 'AMAZON.COM INC',
 'AMAZON.COM INC',
 'AMAZON.COM INC',
 'AMAZON.COM INC',
 'AMAZON.COM INC',
 'AMAZON.COM INC',
 'AMAZON.COM INC')
In[24]: ratios
Out[23]: 
('TOT RETURN IND',
 'NET CASH FLOW-OPERATING ACTIVS',
 'COST OF GOODS SOLD (EXCL DEP)',
 'EARNINGS BEF INTEREST & TAXES',
 'EBIT & DEPRECIATION',
 'GROSS INCOME',
 'NET SALES OR REVENUES',
 'OPERATING INCOME',
 'NET INCOME AVAILABLE TO COMMON',
 'ACCOUNTS PAYABLE',
 'CASH',
 "COMMON SHAREHOLDERS' EQUITY",
 'CURRENT LIABILITIES-TOTAL',
 'TOTAL INVENTORIES',
 'LONG TERM DEBT',
 'TOTAL ASSETS')

1

solved Split list of lists in new list [closed]