Home > Mobile >  how would I single out a group of letters with pythons input() function? [duplicate]
how would I single out a group of letters with pythons input() function? [duplicate]

Time:10-09

for example how could I separate ticker symbols with input(or if you have a better solution to this problem)

tickers = input("Enter tickers:")
upper_tickers = tickers.upper()
print(upper_tickers)


result = "AAPL GME F BABA"

How could I set each ticker to be its own variable so I can run each variable(ticker) though another function.

So some hypothetical code that i'm looking for would be:

input('Input tickers:')
upper_tickers = tickers.upper()
for ticker in upper_tickers:
    print(ticker)

returns: AAPL BABA F GME instead of: A A P etc

CodePudding user response:

upper_tickers.split() will give you a list of tickers that you could loop over, assuming tickers is a whitespace-delimited string of tickers:

for ticker in upper_ticker.split():
    print(ticker)

# output:
"AAPL"
"GME"
"F"
"BABA"

CodePudding user response:

You can use the split method to get a list

upper_tickers = tickers.upper().split(' ')
for ticker in upper_tickers:
    print(ticker)

this way, you would end up with a list ['ONE', 'TWO', 'THREE']

and can use them like this to call a function with each element.

Lists are great :) Here's some more info.

  • Related