0
$\begingroup$

How would I translate this code into a mathematical formula?

myset={4,2,5,26,8,1,2}, d0=[], d1=[], dnp1=[] for i in range(myset):     if   i==0: d0=myset[i]     elif i==1: d1=myset[i]     else:      dnp1+=myset[i] 

(a $\LaTeX$ example would be great)

  • 0
    If $i \in \{4, 2, 5, 26, 8, 1, 2\}$ then how come you test for $i = 0$?! $i$ will never be zero.2012-07-06

1 Answers 1

1

Here's one solution (I devised myself):

$ \sum_{i}^{\text{myset}} d_0=\{ \unicode{x27E6}i==0\unicode{x27E7}\ i \},\ d_1=\{ \unicode{x27E6}i==1\unicode{x27E7}\ i \},\ d_{np1}=\{ \unicode{x27E6}i>1\unicode{x27E7}\ i \} $

  • 0
    @J.M. Sure. But this question is two folded (1) how do I formulate it? (2) is my following *attempt* correct? Answering (2) is much easier if all OP's *attempts* are in 1 place: the question body.2012-07-06