[Zope] HOW TO COUNT VARIABLE WITH <DTML-IN>
Mike Doanh Tran
mtran@shufflemasterrd.com
Mon, 16 Dec 2002 16:14:22 -0700
Thank you very much, that works great! I was messing with it in DTML
and it got kind of nasty.
Mike
On Monday 16 December 2002 04:04 pm, Tino Wildenhain wrote:
> Hi Mike,
>
> --On Montag, 16. Dezember 2002 15:32 -0700 Mike Doanh Tran
>
> <mtran@shufflemasterrd.com> wrote:
> > How do i count the value of a variable inside of <dtml-in>
> > I want to count not just the occurence of the variable but the
> > value of that variable also. For Example i have a variable name "weight":
> >
> > <dtml-in getQuery>
> > <dtml-var count-weight>
> > </dtml-in getQuery>
> >
> > <dtml-var count-weight> will give me a total number of occurence for the
> > variable weight. What i want to do is count the value of weight.
> >
> > if weight=1 then count how many 1 there are
> > if weight=2 then count how many 2 there are
> > and so on ....
>
> While it is possible in DTML, I show you a solution with lesser pain:
> Add a python script and use a construct like that:
>
> weights={}
> for line in context.getQuery():
> weights[line.weight]=weights.get(line.weight,0)+1
>
> return weights
>
>
> The script will start with an empty dictionary (hash, associative array)
> and for any value of weight, it looks up the current value with this
> kay in the dictionary, using 0 as default if none is found and adds 1
> to it. In the result you have a dictionary which maps each value
> for weight to the count of this value.
>
> HTH
> Tino Wildenhain
>
>
> _______________________________________________
> Zope maillist - Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> ** No cross posts or HTML encoding! **
> (Related lists -
> http://lists.zope.org/mailman/listinfo/zope-announce
> http://lists.zope.org/mailman/listinfo/zope-dev )
--
Mike Doanh Tran
Shuffle Master Inc.
R&D Website: http://internal.shufflemasterrd.com/