Friday 15 May 2015

dictionary - python TypeError unhashable type: dict cant find the set to freeze -



dictionary - python TypeError unhashable type: dict cant find the set to freeze -

i've looked @ next links figure out should freeze code

typeerror: unhashable type: 'dict'

troubleshooting "typeerror: unhashable type: 'dict'"

typeerror: unhashable type: 'dict' in python

def getpx (self, date, instrument, item = 'adj close', prices = none): ''' cost instrument on date prices table''' prices = prices or self.prices import datetime import numpy np if type ( instrument ) == np.ndarray: instrument = str ( instrument [ 0 ] ) pricelist = [item.copy() item in prices[instrument]] item in pricelist: item['date'] = datetime.datetime.strptime(item['date'],"%y-%m-%d") dates = map(lambda x: x['date'],pricelist) eff_date = max([d d in dates if d <= date]) cost = [price[item] cost in pricelist if price["date"] == eff_date] homecoming cost

where pricelist dict can't seem figure out freeze. wasted whole morning trying figure out why can't cost @ particular date dictionary..

any help appreciated

edit:

a typical illustration pricelist be

{'abcd':{'adj close': '82.72', 'close': '86.06', 'date': '2013-09-19', 'high': '86.90', 'low': '85.79', 'open': '86.86', 'volume': '18700'}, {'adj close': '83.67', 'close': '87.05', 'date': '2013-09-18', 'high': '87.75', 'low': '85.18', 'open': '85.49', 'volume': '30900'}, {'adj close': '82.48', 'close': '85.81', 'date': '2013-09-17', 'high': '85.85', 'low': '85.02', 'open': '85.12', 'volume': '14700'}, {'adj close': '81.43', 'close': '84.72', 'date': '2013-09-16', 'high': '86.36', 'low': '84.42', 'open': '86.18', 'volume': '4700'}, {'adj close': '82.16', 'close': '85.48', 'date': '2013-09-13', 'high': '86.31', 'low': '85.12', 'open': '85.98', 'volume': '205000'}, {'adj close': '82.10', 'close': '85.42', 'date': '2013-09-12', 'high': '86.60', 'low': '85.08', 'open': '86.33', 'volume': '16000'}, {'adj close': '82.15', 'close': '85.47', 'date': '2013-09-11', 'high': '85.47', 'low': '84.47', 'open': '85.14', 'volume': '9700'}}

in price = [price[item] cost in pricelist if price["date"] == eff_date] line, using item used in loop:

for item in pricelist: item['date'] = datetime.datetime.strptime(item['date'],"%y-%m-%d")

item dictionary, cannot utilize key in price dictionary.

python dictionary

No comments:

Post a Comment