I have this long list of words that I want to loop through:
company_name = [Adrian Lee & Partners, Aegon Asset Management, Amundi Asset Management, Australiansuper, Aviva Investors, AXA Investment Management, Bank of America, Bank of England,Banque de Luxembourg,Barclays,Berenberg,Bierbaum Pro ag,BlackRock,BlondeMoney,BlueBay Asset Management,Bluecrest Capital Management,Brevan Howard,China Construction Bank Corporation,Credit Suisse,Credit Suisse Asset Managemenet,Cuemacro,Deutsche Boerse,Dimensional Fund Advisors,Divento Financials limited,Eaton Vance,Edmond De Rothschild Asset management gmbh,Erste Asset Management (EAM),Eurex,ExoAlpha,Fidelity Investments,Financial Times,Findlay Park partners llp,Florin Court Capital LLP,GAM investments,GIC Capital Corp,GSA Capital,H2O AM LLP,ING Bank NV, London Branch,Invesco,International Standard Asset Management,J.P. Morgan,Janus Henderson,JPMorgan Asset Management,Jupiter Asset Management,LCH,Legal & General Investment Management,LMRKTS LLC,Lombard Odier Investment Managers,Man Group,Manulife Investment Management,Metzler Asset Management ,Millennium Global Investments,Morgan Stanley,Morgan Stanley Investment Management,Moscow Exchange,Ninety One,Nomura Asset Management,Norges Bank Investment Management,Optiver,Payden & Rygel,Pictet Asset Management,Pimco,Principal Global Investors,Putnam Investments,Record Currency Management,Renaissance Capital,Rokos Capital Management,Russell Investments,Schroders,State Street,Systematica Investments,T. Rowe Price,Tellurian Capital Management llp,Thalesians ltd,UBS,UBS Asset Management,Union Investment institutional,United National Bank,USS Investment Management,Wellington Management,White Oak Asset Management,Winton,Zürcher Kantonalbank,VZ Depotbank AG,eToro,Daiwa Capital Markets,VTB Capital,Sberbank,BNY Mellon | Pershing,Livi Bank,Wells Fargo Securities,Bank Leumi,RedBurn,VTB Capital,MUFG,ICAP,Moore Capital,Mizuho Bank,Prescient,RBC Capital Markets,Peel Hunt,KBC Secutiries,Swedbank,Sparebank1,Man Group,Jefferies,Nedbank,Avior Capital Markets (pty) ltd,Avalon Capital Markets,Neveus,Forte Securities limited,BOCI,Zeus Capital,BMO Capital Markets,China Merchants Securities co. ltd,IG Group,Handelsbanken,TD Securities,BNP Paribas,Unicredit,mitsubishi ufj lease & finance co. ltd.,ING Bank,nordea markets, corporates & institutions,Commonwealth Bank of Australia,Danske Bank,Wiener Privatbank se,ABSA Bank SA,HSBC,Canaccord Genuity- Global Capital Markets,Dowgate Capital Limited,Trium Capital,BTIG,Sova Capital,Saxo Bank,Cantor fitzgerald,FinnCap group,BBVA,M.M.Warburg & CO,Bank of Tokyo UFG,lseg (London Stock Exchange Group),Kotak securities,CF Global Trading,Liberum Capital Participações Ltda,Rand Merchant Bank,Cathay United Bank,Steubing ag,Credit Agricole cib,Arden Partners,Banco de Investimento Global (BIG),BMO Capital Markets,Panmure Gordon & co,Santander bank,Deutsche Bank,Mizuho Securities,Numis,Bainbridge partners llp,Jutlander Bank,Cirdan Capital,MWB FairTrade ag,Rezco Asset Management,Shore Capital markets,Hobart Capital Markets llp,Baader Bank ag,Linear Investment ltd,Arion Banki,Kotak Securities]
I am getting a syntax error which I believe is a result of the words not being in quotation marks. If this is the case, is there a way to code it to put them all in quotes or do I have to do it manually? If this is not the reason for a syntax error, can anybody see what is wrong here?
Thanks!
CodePudding user response:
Whenever I have one of these issues, it helps to fire up Sublime Text and do a quick find-replace.
In this case, you'll want your data to look like this in order for Python to be able to read it:
company_names = ['Adrian Lee & Partners','Aegon Asset Management','Amundi Asset Management','Australiansuper','Aviva Investors','AXA Investment Management','Bank of America','Bank of England','Banque de Luxembourg','Barclays','Berenberg','Bierbaum Pro ag','BlackRock','BlondeMoney','BlueBay Asset Management','Bluecrest Capital Management','Brevan Howard','China Construction Bank Corporation','Credit Suisse','Credit Suisse Asset Managemenet','Cuemacro','Deutsche Boerse','Dimensional Fund Advisors','Divento Financials limited','Eaton Vance','Edmond De Rothschild Asset management gmbh','Erste Asset Management (EAM)','Eurex','ExoAlpha','Fidelity Investments','Financial Times','Findlay Park partners llp','Florin Court Capital LLP','GAM investments','GIC Capital Corp','GSA Capital','H2O AM LLP','ING Bank NV',' London Branch','Invesco','International Standard Asset Management','J.P. Morgan','Janus Henderson','JPMorgan Asset Management','Jupiter Asset Management','LCH','Legal & General Investment Management','LMRKTS LLC','Lombard Odier Investment Managers','Man Group','Manulife Investment Management','Metzler Asset Management ','Millennium Global Investments','Morgan Stanley','Morgan Stanley Investment Management','Moscow Exchange','Ninety One','Nomura Asset Management','Norges Bank Investment Management','Optiver','Payden & Rygel','Pictet Asset Management','Pimco','Principal Global Investors','Putnam Investments','Record Currency Management','Renaissance Capital','Rokos Capital Management','Russell Investments','Schroders','State Street','Systematica Investments','T. Rowe Price','Tellurian Capital Management llp','Thalesians ltd','UBS','UBS Asset Management','Union Investment institutional','United National Bank','USS Investment Management','Wellington Management','White Oak Asset Management','Winton','Zürcher Kantonalbank','VZ Depotbank AG','eToro','Daiwa Capital Markets','VTB Capital','Sberbank','BNY Mellon | Pershing','Livi Bank','Wells Fargo Securities','Bank Leumi','RedBurn','VTB Capital','MUFG','ICAP','Moore Capital','Mizuho Bank','Prescient','RBC Capital Markets','Peel Hunt','KBC Secutiries','Swedbank','Sparebank1','Man Group','Jefferies','Nedbank','Avior Capital Markets (pty) ltd','Avalon Capital Markets','Neveus','Forte Securities limited','BOCI','Zeus Capital','BMO Capital Markets','China Merchants Securities co. ltd','IG Group','Handelsbanken','TD Securities','BNP Paribas','Unicredit','mitsubishi ufj lease & finance co. ltd.','ING Bank','nordea markets','corporates & institutions','Commonwealth Bank of Australia','Danske Bank','Wiener Privatbank se','ABSA Bank SA','HSBC','Canaccord Genuity- Global Capital Markets','Dowgate Capital Limited','Trium Capital','BTIG','Sova Capital','Saxo Bank','Cantor fitzgerald','FinnCap group','BBVA','M.M.Warburg & CO','Bank of Tokyo UFG','lseg (London Stock Exchange Group)','Kotak securities','CF Global Trading','Liberum Capital Participações Ltda','Rand Merchant Bank','Cathay United Bank','Steubing ag','Credit Agricole cib','Arden Partners','Banco de Investimento Global (BIG)','BMO Capital Markets','Panmure Gordon & co','Santander bank','Deutsche Bank','Mizuho Securities','Numis','Bainbridge partners llp','Jutlander Bank','Cirdan Capital','MWB FairTrade ag','Rezco Asset Management','Shore Capital markets','Hobart Capital Markets llp','Baader Bank ag','Linear Investment ltd','Arion Banki','Kotak Securities']
CodePudding user response:
Obviously the problem is that all strings are not quoted.
company_name = "Adrian Lee & Partners, Aegon Asset Management, Amundi Asset Management, Australiansuper, Aviva Investors, AXA Investment Management, Bank of America, Bank of England,Banque de Luxembourg,Barclays,Berenberg,Bierbaum Pro ag,BlackRock,BlondeMoney,BlueBay Asset Management,Bluecrest Capital Management,Brevan Howard,China Construction Bank Corporation,Credit Suisse,Credit Suisse Asset Managemenet,Cuemacro,Deutsche Boerse,Dimensional Fund Advisors,Divento Financials limited,Eaton Vance,Edmond De Rothschild Asset management gmbh,Erste Asset Management (EAM),Eurex,ExoAlpha,Fidelity Investments,Financial Times,Findlay Park partners llp,Florin Court Capital LLP,GAM investments,GIC Capital Corp,GSA Capital,H2O AM LLP,ING Bank NV, London Branch,Invesco,International Standard Asset Management,J.P. Morgan,Janus Henderson,JPMorgan Asset Management,Jupiter Asset Management,LCH,Legal & General Investment Management,LMRKTS LLC,Lombard Odier Investment Managers,Man Group,Manulife Investment Management,Metzler Asset Management ,Millennium Global Investments,Morgan Stanley,Morgan Stanley Investment Management,Moscow Exchange,Ninety One,Nomura Asset Management,Norges Bank Investment Management,Optiver,Payden & Rygel,Pictet Asset Management,Pimco,Principal Global Investors,Putnam Investments,Record Currency Management,Renaissance Capital,Rokos Capital Management,Russell Investments,Schroders,State Street,Systematica Investments,T. Rowe Price,Tellurian Capital Management llp,Thalesians ltd,UBS,UBS Asset Management,Union Investment institutional,United National Bank,USS Investment Management,Wellington Management,White Oak Asset Management,Winton,Zürcher Kantonalbank,VZ Depotbank AG,eToro,Daiwa Capital Markets,VTB Capital,Sberbank,BNY Mellon | Pershing,Livi Bank,Wells Fargo Securities,Bank Leumi,RedBurn,VTB Capital,MUFG,ICAP,Moore Capital,Mizuho Bank,Prescient,RBC Capital Markets,Peel Hunt,KBC Secutiries,Swedbank,Sparebank1,Man Group,Jefferies,Nedbank,Avior Capital Markets (pty) ltd,Avalon Capital Markets,Neveus,Forte Securities limited,BOCI,Zeus Capital,BMO Capital Markets,China Merchants Securities co. ltd,IG Group,Handelsbanken,TD Securities,BNP Paribas,Unicredit,mitsubishi ufj lease & finance co. ltd.,ING Bank,nordea markets, corporates & institutions,Commonwealth Bank of Australia,Danske Bank,Wiener Privatbank se,ABSA Bank SA,HSBC,Canaccord Genuity- Global Capital Markets,Dowgate Capital Limited,Trium Capital,BTIG,Sova Capital,Saxo Bank,Cantor fitzgerald,FinnCap group,BBVA,M.M.Warburg & CO,Bank of Tokyo UFG,lseg (London Stock Exchange Group),Kotak securities,CF Global Trading,Liberum Capital Participações Ltda,Rand Merchant Bank,Cathay United Bank,Steubing ag,Credit Agricole cib,Arden Partners,Banco de Investimento Global (BIG),BMO Capital Markets,Panmure Gordon & co,Santander bank,Deutsche Bank,Mizuho Securities,Numis,Bainbridge partners llp,Jutlander Bank,Cirdan Capital,MWB FairTrade ag,Rezco Asset Management,Shore Capital markets,Hobart Capital Markets llp,Baader Bank ag,Linear Investment ltd,Arion Banki,Kotak Securities".split(", ")
CodePudding user response:
just place a quotation mark after [
and before ]
then after quotation mark write .split(",") and remove those square brackets like:
company_name = "Adrian Lee & Partners, Aegon Asset Management, Amundi Asset Management, Australiansuper, Aviva Investors, AXA Investment Management, Bank of America, Bank of England,Banque de Luxembourg,Barclays,Berenberg,Bierbaum Pro ag,BlackRock,BlondeMoney,BlueBay Asset Management,Bluecrest Capital Management,Brevan Howard,China Construction Bank Corporation,Credit Suisse,Credit Suisse Asset Managemenet,Cuemacro,Deutsche Boerse,Dimensional Fund Advisors,Divento Financials limited,Eaton Vance,Edmond De Rothschild Asset management gmbh,Erste Asset Management (EAM),Eurex,ExoAlpha,Fidelity Investments,Financial Times,Findlay Park partners llp,Florin Court Capital LLP,GAM investments,GIC Capital Corp,GSA Capital,H2O AM LLP,ING Bank NV, London Branch,Invesco,International Standard Asset Management,J.P. Morgan,Janus Henderson,JPMorgan Asset Management,Jupiter Asset Management,LCH,Legal & General Investment Management,LMRKTS LLC,Lombard Odier Investment Managers,Man Group,Manulife Investment Management,Metzler Asset Management ,Millennium Global Investments,Morgan Stanley,Morgan Stanley Investment Management,Moscow Exchange,Ninety One,Nomura Asset Management,Norges Bank Investment Management,Optiver,Payden & Rygel,Pictet Asset Management,Pimco,Principal Global Investors,Putnam Investments,Record Currency Management,Renaissance Capital,Rokos Capital Management,Russell Investments,Schroders,State Street,Systematica Investments,T. Rowe Price,Tellurian Capital Management llp,Thalesians ltd,UBS,UBS Asset Management,Union Investment institutional,United National Bank,USS Investment Management,Wellington Management,White Oak Asset Management,Winton,Zürcher Kantonalbank,VZ Depotbank AG,eToro,Daiwa Capital Markets,VTB Capital,Sberbank,BNY Mellon | Pershing,Livi Bank,Wells Fargo Securities,Bank Leumi,RedBurn,VTB Capital,MUFG,ICAP,Moore Capital,Mizuho Bank,Prescient,RBC Capital Markets,Peel Hunt,KBC Secutiries,Swedbank,Sparebank1,Man Group,Jefferies,Nedbank,Avior Capital Markets (pty) ltd,Avalon Capital Markets,Neveus,Forte Securities limited,BOCI,Zeus Capital,BMO Capital Markets,China Merchants Securities co. ltd,IG Group,Handelsbanken,TD Securities,BNP Paribas,Unicredit,mitsubishi ufj lease & finance co. ltd.,ING Bank,nordea markets, corporates & institutions,Commonwealth Bank of Australia,Danske Bank,Wiener Privatbank se,ABSA Bank SA,HSBC,Canaccord Genuity- Global Capital Markets,Dowgate Capital Limited,Trium Capital,BTIG,Sova Capital,Saxo Bank,Cantor fitzgerald,FinnCap group,BBVA,M.M.Warburg & CO,Bank of Tokyo UFG,lseg (London Stock Exchange Group),Kotak securities,CF Global Trading,Liberum Capital Participações Ltda,Rand Merchant Bank,Cathay United Bank,Steubing ag,Credit Agricole cib,Arden Partners,Banco de Investimento Global (BIG),BMO Capital Markets,Panmure Gordon & co,Santander bank,Deutsche Bank,Mizuho Securities,Numis,Bainbridge partners llp,Jutlander Bank,Cirdan Capital,MWB FairTrade ag,Rezco Asset Management,Shore Capital markets,Hobart Capital Markets llp,Baader Bank ag,Linear Investment ltd,Arion Banki,Kotak Securities".split(", ")
it will give you list of company name in variable company_name
to extract words from these names
words = [word for word in name.split() for name in company_name]
and there you go ;)