A memorandum of knowledge that I encountered while implementing Takashi-kun problem. I learned that it is necessary to write multiple for statements in one sentence when using pulp. I still feel the lack of writing power. .. ..
for x in range(4):
for y in range(3):
for z in range(2):
print(x,y,z)
>>0 0 0
>>0 0 1
>>0 1 0
>>0 1 1
>>0 2 0
>>0 2 1 ...
Is
[(x,y,z) for x in range(4) for y in range(3) for z in range(2)]
>>[(0, 0, 0),
>> (0, 0, 1),
>> (0, 1, 0),
>> (0, 1, 1),
>> (0, 2, 0),
>> (0, 2, 1), ...
for x in range(4):
if x ==3:
for y in range(3):
for z in range(2):
print(x,y,z)
>>3 0 0
>>3 0 1
>>3 1 0
>>3 1 1
>>3 2 0
>>3 2 1
Is
[(x,y,z) for x in range(4) if x == 3 for y in range(3) for z in range(2)]
>>[(3, 0, 0), (3, 0, 1), (3, 1, 0), (3, 1, 1), (3, 2, 0), (3, 2, 1)]
for x in range(4):
if x ==3:
for y in range(3):
for z in range(2):
if z == 1:
print(x,y,z)
>>3 0 1
>>3 1 1
>>3 2 1
Is
[(x,y,z) for x in range(4) if x == 3 for y in range(3) for z in range(2) if z == 1]
>>[(3, 0, 1), (3, 1, 1), (3, 2, 1)]
The order in which the for statement turns is complicated.
Recommended Posts