0

So if I assigned a to a string with the character b in it, how do I get the character from the a string and use it to assign it to another value?

I tried:

a = "b"
a.strip("") = 2
# so that b = 2
print(b)
>> 2

I need it because I have a list with stock ticker symbols and want to access it when I iterate through the ticker symbol list. eg.

tickers = ["TSLA", "SPCE"]
for i in range(len(tickers)):
    print(tickers[i]["Adj Close"])

This however throws out an error.

Thank you in advance

Coder
  • 75
  • 6
  • 1
    `d = {'TSLA': [.....], 'SPCE': [.....]}`; `d[tickers[i]]['Adj Close']` – cs95 Dec 24 '20 at 11:55
  • 1
    Althouh possible, it's considered bad practice to create named variables in this way i.e. [dynamically creating variables in python](https://stackoverflow.com/questions/51195607/dynamically-creating-variables-in-python). The recommendation is to use a dictionary for your use case. – DarrylG Dec 24 '20 at 11:58

0 Answers0