I am trying to create a portfolio class. I want to zip my two lists into a dictionary but when a i try to print it out, it is empty(even though my lists are not). Am i missing something??
import numpy as np
class Portfolio(object):
"""description of class"""
array_of_stock_prices=[]
array_of_stock_names=[]
#create a dictionary of stocks
stocks=dict(zip(array_of_stock_names,array_of_stock_prices))
def __init__(self):
print()
def AddStock(self,stock_ticker,stock_price):
self.array_of_stock_names.append(stock_ticker)
self.array_of_stock_prices.append(stock_price)
def printObject(self):
for key,value in self.stocks.items():
print(key,value)
port1=Portfolio()
port1.AddStock('AApl',100)
port1.printObject()
stocksonly once.Addstocki.e. the dict is created before your lists have any values. None of your functions modifies the dictionary, so it remains empty.array_of_stock_prices, ` array_of_stock_names` andstocksare class attributes (shared between all instances of the class). I don't think that's what you want.