Understanding Python Code

Ian Kelly ian.g.kelly at gmail.com
Thu Jun 19 15:07:01 EDT 2014


On Thu, Jun 19, 2014 at 12:44 PM,  <subhabangalore at gmail.com> wrote:
> Dear Group,
> Generally most of the issues are tackled here, but as I am trying to cross check my understanding I found another question,
>
> f_curr[st] = e[st][x_i] * prev_f_sum
>
> Here, if I give one print command and see the results,
> print "$$2",f_curr
>
> It is showing an iterative update like,
> $$2 {'Healthy': 0.3},
> $$2 {'Healthy': 0.3, 'Fever': 0.04000000000000001}
>
> I was trying to ask how the size is being updated, from 1 to 2 back to 1 again 2... is it for any loop then which one, I tried to change but not being able
> to if any one of the esteemed members may kindly help me.

That statement is inside the for loop that builds the f_curr dict. One
state gets calculated on each iteration. The first time it prints, one
state has been added. The second time it prints, two states have been
added. You only have two states, so at that point the loop is done.
The next time it prints, it's on the next iteration of the outer (i,
x_i) loop and it's building a new f_curr dict. So then you see it
adding one state and then the second state to the new dict. And so on
and so forth until the outer loop completes.



More information about the Python-list mailing list