Skip to main content
spell out consequence of non-complementary conditions
Source Link
greybeard
  • 7.8k
  • 3
  • 21
  • 56
  • the output does seem to depend on the order of elements of lista
    (even beyond its order: lista[3][i-1])
    • hope lista[2][i] >= listc[1][j] is never True for i 0
    (unless you want lista[3][-1] accessed)
  • the output does not seem to depend on the order of elements of listc
  • both lista and listc are not changed
    → the "range conditions" won't change unless at least one index changes
  • all of "the increments" share the condition lista[0][i] == listc[0][j]
  • the conditions between lista[6/7][i] and listc[1][j] are not complementary for including equality in both cases
  • implying red/green possibly getting incremented twice in a single iteration (not using else)
  • the output does seem to depend on the order of elements of lista
    (even beyond its order: lista[3][i-1])
    • hope lista[2][i] >= listc[1][j] is never True for i 0
    (unless you want lista[3][-1] accessed)
  • the output does not seem to depend on the order of elements of listc
  • both lista and listc are not changed
    → the "range conditions" won't change unless at least one index changes
  • all of "the increments" share the condition lista[0][i] == listc[0][j]
  • the conditions between lista[6/7][i] and listc[1][j] are not complementary for including equality in both cases
  • the output does seem to depend on the order of elements of lista
    (even beyond its order: lista[3][i-1])
    • hope lista[2][i] >= listc[1][j] is never True for i 0
    (unless you want lista[3][-1] accessed)
  • the output does not seem to depend on the order of elements of listc
  • both lista and listc are not changed
    → the "range conditions" won't change unless at least one index changes
  • all of "the increments" share the condition lista[0][i] == listc[0][j]
  • the conditions between lista[6/7][i] and listc[1][j] are not complementary for including equality in both cases
  • implying red/green possibly getting incremented twice in a single iteration (not using else)
recommend tool support
Source Link
greybeard
  • 7.8k
  • 3
  • 21
  • 56
  • document, in the code, what is to be achieved
    Python supports this with docstrings
  • use telling names
  • have a tool help you sticking to The Python Style Guide
  • order listc
  • for each i, iterate only that part of the ordered listc where lista[0][i] == listc[0][j]
  • ignore if lista and listc are not "rectangular":

food for thought: untested result of refactoring (extractingget tool support for such, too)
(here extracting local variables, mostly)

  • document, in the code, what is to be achieved
    Python supports this with docstrings
  • use telling names
  • order listc
  • for each i, iterate only that part of the ordered listc where lista[0][i] == listc[0][j]
  • ignore if lista and listc are not "rectangular":

food for thought: untested result of refactoring (extracting local variables, mostly)

  • document, in the code, what is to be achieved
    Python supports this with docstrings
  • use telling names
  • have a tool help you sticking to The Python Style Guide
  • order listc
  • for each i, iterate only that part of the ordered listc where lista[0][i] == listc[0][j]
  • ignore if lista and listc are not "rectangular":

food for thought: untested result of refactoring (get tool support for such, too)
(here extracting local variables, mostly)

added 1 character in body
Source Link
greybeard
  • 7.8k
  • 3
  • 21
  • 56
list_c = sorted(listc)
for i in range(len(lista[1])):
    red = green = black = 0
    a0i = lista[0][i]
    first = bisect_left(list_c[1], a0i)
    beyond = bisect_leftbisect_right(list_c[1], a0i, first)
    if first < beyond:
        a2i = lista[2][i]
        a3i = lista[3][i]
        c2i = list_c[2][i]
        a8i_intended = lista[8][i] == 'intended value'
        for j in range(first, beyond):
            c1j = list_c[1][j]
            if (c1j <= a3i or c1j >= a2i):
                if lista[7][i] >= c1j and lista[6][i] <= c1j and a8i_intended:
                    red += c2i
                if a3i >= c1j and lista[7][i] <= c1j and not a8i_intended:
                    red += c2i
                if lista[6][i] >= c1j and a2i <= c1j and a8i_intended:
                    green += c2i
                if lista[7][i] >= c1j and a2i <= c1j and not a8i_intended:
                    green += c2i
                if a2i >= c1j and lista[3][i - 1] <= c1j:
                    black += c2i
    toc = timeit.default_timer()
    if i % 100 == 0:
        print('processing algorithm: {}'.format(toc - tic))
        print('we are at row {}'.format(i))
    output[0].append(lista[1][i])
    output[1].append(red)
    output[2].append(green)
    output[3].append(black)
list_c = sorted(listc)
for i in range(len(lista[1])):
    red = green = black = 0
    a0i = lista[0][i]
    first = bisect_left(list_c[1], a0i)
    beyond = bisect_left(list_c[1], a0i, first)
    if first < beyond:
        a2i = lista[2][i]
        a3i = lista[3][i]
        c2i = list_c[2][i]
        a8i_intended = lista[8][i] == 'intended value'
        for j in range(first, beyond):
            c1j = list_c[1][j]
            if (c1j <= a3i or c1j >= a2i):
                if lista[7][i] >= c1j and lista[6][i] <= c1j and a8i_intended:
                    red += c2i
                if a3i >= c1j and lista[7][i] <= c1j and not a8i_intended:
                    red += c2i
                if lista[6][i] >= c1j and a2i <= c1j and a8i_intended:
                    green += c2i
                if lista[7][i] >= c1j and a2i <= c1j and not a8i_intended:
                    green += c2i
                if a2i >= c1j and lista[3][i - 1] <= c1j:
                    black += c2i
    toc = timeit.default_timer()
    if i % 100 == 0:
        print('processing algorithm: {}'.format(toc - tic))
        print('we are at row {}'.format(i))
    output[0].append(lista[1][i])
    output[1].append(red)
    output[2].append(green)
    output[3].append(black)
list_c = sorted(listc)
for i in range(len(lista[1])):
    red = green = black = 0
    a0i = lista[0][i]
    first = bisect_left(list_c[1], a0i)
    beyond = bisect_right(list_c[1], a0i, first)
    if first < beyond:
        a2i = lista[2][i]
        a3i = lista[3][i]
        c2i = list_c[2][i]
        a8i_intended = lista[8][i] == 'intended value'
        for j in range(first, beyond):
            c1j = list_c[1][j]
            if (c1j <= a3i or c1j >= a2i):
                if lista[7][i] >= c1j and lista[6][i] <= c1j and a8i_intended:
                    red += c2i
                if a3i >= c1j and lista[7][i] <= c1j and not a8i_intended:
                    red += c2i
                if lista[6][i] >= c1j and a2i <= c1j and a8i_intended:
                    green += c2i
                if lista[7][i] >= c1j and a2i <= c1j and not a8i_intended:
                    green += c2i
                if a2i >= c1j and lista[3][i - 1] <= c1j:
                    black += c2i
    toc = timeit.default_timer()
    if i % 100 == 0:
        print('processing algorithm: {}'.format(toc - tic))
        print('we are at row {}'.format(i))
    output[0].append(lista[1][i])
    output[1].append(red)
    output[2].append(green)
    output[3].append(black)
Source Link
greybeard
  • 7.8k
  • 3
  • 21
  • 56
Loading