'NoneType' object is not iterable: Loop for a list

Viewed 20

I am trying to convert a loop for a list, but i'm getting the 'NoneType' object is not iterable' error.

assets = input("What assets you desire to analyze?v: ").upper().split(",")
for ticker in assets:
  assets1 = print(ticker + ".SA")

When i print "assets1", i get a output like this:

PGMN3.SA
COGN3.SA
TASA4.SA
PCAR3.SA
PETZ3.SA

But i wish to make this loop as a list, to do a WebScraping after, but when put "assets1" for webscraping, i get the message error: 'NoneType' object is not iterable' How can i fix it? Thanks!

1 Answers

print() function return None - so you're only printing the tickers, not storing them in anything. This example uses list-comprehension to add .SA to each ticker and store it in a list names assets:

assets = input("What assets you desire to analyze?").upper().split(",")
assets = [ticker + ".SA" for ticker in assets]

print(assets)

Prints (for example):

What assets you desire to analyze?PGMN3,COGN3,TASA4,PCAR3,PETZ3
['PGMN3.SA', 'COGN3.SA', 'TASA4.SA', 'PCAR3.SA', 'PETZ3.SA']
Related