Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

For cycles over n-uples

Is it possible to run a for cyle over an n-uple? I give an example with a code that doesn't work as intended: I want to write, for A=[1,2] B=[3,4], something like

  for a,b in A,B:
     print(a,b)

and obtain the following

    1,3
    1,4
    1,5
    1,6

I know in this case I could use

 for a in A:
     for b in B:
          print(a,b)

but in the code I'm writing this is not ideal, besically beacuse I want to do stuff with each of the vectors in the following way

c=[]
for a in A:
      f=function
      c.append(f(a))
      for b in B: 
            c.append(f(b))
      do stuff with c, reset c to []

and in this case is harder to have c made of only 2 elements.

I hope what I mean is clear

For cycles over n-uples

Is it possible to run a for cyle over an n-uple? I give an example with a code that doesn't work as intended: I want to write, for A=[1,2] B=[3,4], something like

  for a,b in A,B:
     print(a,b)

and obtain the following

    1,3
    1,4
    1,5
    1,6

I know in this case I could use

 for a in A:
     for b in B:
          print(a,b)

but in the code I'm writing this is not ideal, besically basically beacuse I want to do stuff with each of the vectors in the following way

c=[]
for a in A:
A=[[],...[]]
n=len(A)
for x in range(n):
  for a in A[x]:
      f=function
      c.append(f(a))
      for b in B: 
            c.append(f(b))
      do stuff with c, reset c to []
[] in order to repete with different elements

and in this case is harder to have c made of only 2 elements.the way I want it to be made.

I hope what I mean is clear clear

For cycles over n-uples

Is it possible to run a for cyle over an n-uple? I give an example with a code that doesn't work as intended: I want to write, for A=[1,2] B=[3,4], something like

  for a,b in A,B:
     print(a,b)

and obtain the following

    1,3
    1,4
    1,5
    1,6

I know in this case I could use

 for a in A:
     for b in B:
          print(a,b)

but in the code I'm writing this is not ideal, basically beacuse I want to do stuff with each of the vectors in the following way

c=[]
A=[[],...[]]
n=len(A)
for x in range(n):
  for a in A[x]:
      f=function
      c.append(f(a))
      do stuff with c, reset c to [] in order to repete with different elements

and in this case is harder to have c made the way I want it to be made.

I hope what I mean is clear

EDIT: To be more precise what I have is a set C[[C1], [Cn]] where n depends on the imput and the CI are themself sets I want to build (and check a given property) vectors of the type [c1, f1(c1), f1^2(c1),...f1^(e1)(c1),.....fn^(en)(cn)] for ci in CI

Trying to do it in the "traditional way" has the problem of storing the half built vectors. Let's suppose I've built the vector until [c1, f1(c1), f1^2(c1),...f1^(e1)(c1),.....f(n-1)^(e(n-1))(c(n-1))] now I can add the last bunch of components and check if the property is satisfied, but if I want to check the same with a different final bunch (corresponding to a different cn) I have to have stored [c1, f1(c1), f1^2(c1),...f1^(e1)(c1),.....f(n-1)^(e(n-1))(c(n-1))], go back to it and retry.

On the other side if we take a more "mathematical theoretic" approach I don't have this problem where for "mathematical approach" I mean taking (c1,...c_n) in C1 X .... X CN and then just build the final vector from this.

For cycles over n-uples

Is it possible to run a for cyle over an n-uple? I give an example with a code that doesn't work as intended: I want to write, for A=[1,2] B=[3,4], something like

  for a,b in A,B:
     print(a,b)

and obtain the following

    1,3
    1,4
    1,5
    1,6

I know in this case I could use

 for a in A:
     for b in B:
          print(a,b)

but in the code I'm writing this is not ideal, basically beacuse I want to do stuff with each of the vectors in the following way

c=[]
A=[[],...[]]
n=len(A)
for x in range(n):
  for a in A[x]:
      f=function
      c.append(f(a))
      do stuff with c, reset c to [] in order to repete with different elements

and in this case is harder to have c made the way I want it to be made.

I hope what I mean is clear

EDIT: To be more precise what I have is a set C[[C1], [Cn]] where n depends on the imput and the CI are themself sets sets.

I want to build (and check a given property) vectors of the type [c1, f1(c1), f1^2(c1),...f1^(e1)(c1),.....fn^(en)(cn)] for ci in CI

Trying to do it in the "traditional way" has the problem of storing the half built vectors. Let's suppose I've built the vector until [c1, f1(c1), f1^2(c1),...f1^(e1)(c1),.....f(n-1)^(e(n-1))(c(n-1))] now I can add the last bunch of components and check if the property is satisfied, but if I want to check the same with a different final bunch (corresponding to a different cn) I have to have stored [c1, f1(c1), f1^2(c1),...f1^(e1)(c1),.....f(n-1)^(e(n-1))(c(n-1))], go back to it and retry.

On the other side if we take a more "mathematical theoretic" approach I don't have this problem where for "mathematical approach" I mean taking (c1,...c_n) in C1 X .... X CN and then just build the final vector from this.