python - create a list from a functions output? -


i building financial model , stuck on last bit of model have produce graphs output of functions. below final function , didn't put other functions code them large. model shows how (customers, orders, netsales etc) evolve per day through out year different customer type. if run function customer type 12, run day 1 day 365 showing how customers or other stuff have grown.

def show_all_states_list(cust_type):     s  = get_state0(cust_type)         all_states =[]     day in range(365):         s = state_evolution(s, cust_type)         all_states.append(s)     return all_states 

output function day 1 is(not including output) when run in python:

s = show_all_states_list(12) >>> s[0] {'day': 1,'custtypea_nondp': 50.99574423351457,'delfeea_dp_cost': 0.45111124745572373, 'today_ordersa_nondp':0,'profit_current_vs_with_dp ': -5.4141382286616135, 'gross_profit_nondp_dp': 35441.52120017628, 'fixed_costs_nondp_dp ': -56407.52069653516, 'combine_nondp_dp_profit': -5642.694138228653, 'today_netsalesa_nondp': 0, 'gross_turnover_dp_nondp_cust': 142363.5991835414, 'del_nondp_dp_turnover': 28036.11144103729, 'var_costs_nondp_dp': -12712.806082907056, 'custtypea_dp': 0.004255766485431356, 'ordersa_dp': 0.4080111809905219, 'netsalesa_nondp': 114327.45898877166, 'ordersa_nondp': 4444.629080744554, 'today_delfeea_nondp': 0, 'delfeea_nondp': 28035.660329789833, 'totords_dp_nondp': 4445.037091925545,  'today_ordersa_dp': 0, 'gross_turnover_dp_cust': 0.4798649799246596, 'decreased_bsktsize_dp': 0.07047290321586513, 'custtypea': 51.0, 'net_turnover_dp': 0.028753732468935884, 'current_vs_dp_gross_sales': -11.400816458597546} 

what want outputs 365 days take out each key values such 'custtypea_nondp'(so 365 values this) , make new list can plot of days against 'custtypea_nondp' show output graphically.

i know how plot scatter graph don't know how extract information functions output.

i appreciate on this.

dictionaries have convienient values() method need:

>>> d = {'day': 1,'custtypea_nondp': 50.99574423351457,'delfeea_dp_cost': 0.45111124745572373} >>> d.values() [0.45111124745572373, 1, 50.995744233514571] 

the complement keys() method:

>>> d.keys() ['delfeea_dp_cost', 'day', 'custtypea_nondp'] 

your method returns list of dictionaries, if want have list of custtypea_nondp of dictionaries in returned list:

vals = list(x['custtypea_nondp'] x in s) 

Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -