how to make this situation return this result?

Ho Yeung Lee jobmattcon at gmail.com
Sat Jul 1 05:55:01 EDT 2017


i got an idea with below, but it can not compile

for ii, yy in range(2,5), range(0,3):
    for jj, zz in range(2,5), range(0,3):
        if yy < zz:
            print (ii, jj)

real situation

groupkey
{(0, 1): [[0, 1], [0, 2], [0, 8]], (1, 2): [[1, 5], [1, 9], [2, 6], [2, 10], [8, 9], [8, 10]], (2, 3): [[5, 7], [6, 7], [6, 14], [10, 14]]}

ii = 0
jj = 0
for groupkeya in groupkey:
    for groupkeyb in groupkey:
        if ii < jj:
            print "groupkeya"
            print groupkeya, ii, jj
            print "groupkeyb"
            print groupkeyb, ii, jj
        jj = jj + 1
    ii = ii + 1


On Saturday, July 1, 2017 at 5:05:48 PM UTC+8, Ho Yeung Lee wrote:
> sorry for typo,
> 
> iiii = 0
> jjjj = 0
> for ii in range(0,3):
>     for jj in range(0,3):
>         if iiii < jjjj:
>             print (ii, jj)   <----- correct here
>         jjjj = jjjj + 1
>     iiii = iiii + 1
> 
> 
> On Saturday, July 1, 2017 at 4:55:59 PM UTC+8, Ho Yeung Lee wrote:
> > expect result as this first case
> > 
> > ii = 0
> > jj = 0
> > for ii in range(0,3):
> >     for jj in range(0,3):
> >         if ii < jj:
> >             print (ii, jj)
> > 
> > 
> > but below is different
> > as sometimes the situation is not range(0,3), but it a a list of tuple 
> > 
> > iiii = 0
> > jjjj = 0
> > for ii in range(0,3):
> >     for jj in range(0,3):
> >         if iiii < jjjj:
> >             print (iiii, jjjj)
> >         jjjj = jjjj + 1
> >     iiii = iiii + 1
> > 
> > how to make this situation return result like the first case?




More information about the Python-list mailing list