subject ： Yes 5 Arrays of different lengths a1,a2,a3,a4,a5, Now take a number from the array , Form a new array , Request from a1 The number taken out must be less than from a2 Number taken , From the same principle a2 The number taken out must be less than from a3 Number taken , and so on , Lists all arrays that meet the criteria .
The title is quite simple , Take a look at it , And then I used a bunch of them for the first time for loop , The script is as follows ：
a1 = [1,2,4] a2 = [2,3,4,5] a3 = [1,4,7] a4 = [3,6,7,8] a5 = [3,6,8,9,10] for i
in a1: for j in a2: for k in a3: for l in a4: for m in a5: if i<j<k<l<m: print(i
The output is right , But look at this pile for loop , I always feel uncomfortable , After a search , Found out itertools.product(A,
B) This function , This function returns A,B Tuple of Cartesian product of elements in , Seems to meet the conditions , So the script above changes to the following
import itertools for i in itertools.product(a1,a2,a3,a4,a5): if i<i<i<