works in Python 2.7, I have a nested dictionary with some quotation data, from which I would like to create a list of successfully constructed quotes. Currently, here's how I do it:
result = []
for nameStr, nameData in dataTbl.iteritems():
for valueDate, record in nameData.iteritems():
quote = histRecordToQuote(securitiesDict = securitiesDict,
nameStr = nameStr,
valueDate = valueDate,
record = record)
if quote:
result.append(quote)
Is there a more pythonic way to do this? I have a hunch what we can do faster or more clearly with the list. The function histRecordToQuote()returns Nonewhen it cannot construct a quote due to a data error. You can suggest another signature, I will be glad to rewrite it for a clearer / faster code.
Many thanks.
EDIT
Dictionary structure example:
{'IBM': {'20140215':2.53, '20140216':2.55},
'MSFT': {'20140213':2.45, '20140216':0.},
'AMZN': {'20140212':0., '20140214':2.59}}
The parameter securitiesDictis external, it is necessary to build the class Quoteinside histRecordToQuote().
histRecordToQuote() None 0 Quote .
Quote('IBM', '20140215', 2.53)
Quote('IBM', '20140216', 2.55)
Quote('MSFT', '20140213', 2.45)
None
Quote('AMZN', '20140214', 2.59)
None
:
[Quote('IBM', '20140215', 2.53),
Quote('IBM', '20140216', 2.55),
Quote('MSFT', '20140213', 2.45),
Quote('AMZN', '20140214', 2.59)]