注:string
同じ値でも、処理されると異なる max_count 値が返されますが、compute_string_and_return_integer(string)
簡単にするために 3 から 9 の間の乱数が生成されます。
与えられた:
#initial input
[(string, 0),(string, 0),(string,0),(string, 1)]
予想: (生成される最大範囲は前の入力によって異なります)
input = [(string, 0),(string, 0),(string,0),(string, 1)]
max_count = how_many(input) #returns (3,1) #3 is total, and 1 is the 2nd item in list to modify
generate_additional_lists(input, *max_count)
#each of generated lists will aso be used as input to generate the next batch.
[(string, 0),(string, 1),(string,0),(string, 1)] #used as input in ext run
[(string, 0),(string, 2),(string,0),(string, 1)] #used as input in next run
[(string, 0),(string, 3),(string,0),(string, 1)] #used as input again
input2 = [(string, 0),(string, 1),(string,0),(string, 1)]
max_count = how_many(input2) #returns (3,2), where 2 is index which points to 3rd tuple item in the list.
generate_additional_lists(input2, *max_count)
[(string, 0),(string, 1),(string,1),(string, 1)]
[(string, 0),(string, 1),(string,2),(string, 1)]
[(string, 0),(string, 1),(string,3),(string, 1)]
input3 = [(string, 0),(string, 2),(string,0),(string, 1)]
max_count = how_many(input3) #returns (7,2) where 7 is total lists to generate, 2 is index which points to 3rd tuple item in the list.
generate_additional_lists(input3, *max_count)
[(string, 0),(string, 2),(string,1),(string, 1)]
[(string, 0),(string, 2),(string,2),(string, 1)]
[(string, 0),(string, 2),(string,3),(string, 1)]
[(string, 0),(string, 2),(string,4),(string, 1)]
[(string, 0),(string, 2),(string,5),(string, 1)]
[(string, 0),(string, 2),(string,6),(string, 1)]
[(string, 0),(string, 2),(string,7),(string, 1)]
input4 = [(string, 0),(string, 3),(string,0),(string, 1)]
max_count = how_many(input4) #returns (4,2) where 4 is the total and 2 2 is index which points to 3rd tuple item in the list.
generate_additional_lists(input4, *max_count)
[(string, 0),(string, 3),(string,1),(string, 1)]
[(string, 0),(string, 3),(string,2),(string, 1)]
[(string, 0),(string, 3),(string,3),(string, 1)]
[(string, 0),(string, 3),(string,4),(string, 1)]
#we no longer have any lists with tuples that is not first or last containing 0. We stop as we have listed every possible combination.
リストの最初と最後のタプルは変更されず、ずっと同じままです。特定のリストでは、最初と最後の間の各タプルがフォーカスされます。生成されるリストの数は、上記のように文字列の値によって異なります。
私はもともと itertools を使用したデカルト積で十分だと思っていましたが、これには事前に各レベルのタプルの各リストを知る必要があります。入力リストが、インデックスが増加するタプルを含む他のリストがいくつ生成されるかを決定する場合、困難が増します。
def how_many(input_list):
for tuple_index, input in enumerate(input_list):
if input[1] is 0: #signal to generate additional lists but how many?
count = get_max_list_count(input[0]) #pass the string value of thhis
return [count, tuple_index] #returns a list of how many to generate and which tuple to modify
def get_max_list_count(string_from_that_tuple):
return compute_string_and_return_integer(string_from_that_tuple)
#for simplicitys sake, it will return a random integer between 3 and 9. The string value is not important.
def generate_additional_lists(input_list, *max_count):
#max_count[0] contains how many lists to generate
#max_count[1] contains which tuple to modify and increment it's integer value when generating the list
#generate max_count[0] number of lists with the max_count[1]th tuple containing incrementing integer