Tuesday, January 9, 2018

python Recursively build a list based on length and another list

python Recursively build a list based on length and another list



Im trying to make my own version of an octa, and if you try to add different size points , As one level of depth is going down, it will overwrite everything, so it will remove any information on large blocks.

I thought the best way to fix this would be to look back at the previous point, and rebuild the list below to the depth of the new point though, I really can not know that this How to make the list, despite the fact, it is very easy to think about the output after that.

Here is the data that needs to be created with an example in the Start and End list, I need it ["Nodes", (Coordination), "Nodes", (Coordination). .] where each coordinate contains every item in the structure list until it reaches the end.

  structure = [(-1, -1, -1), (-1, -1, 1), (-1), 1, -1), (-1, 1) , 1), (1, -1, -1), (1, -1, 1), (1, 1, -1), (1, 1, 1) nodes, (1, 1, 1) , Nodes, (-1, -1, -1)] end = [nodes, (1, 1, 1), nodes (-1, -1, -1), nodes, ( 1, -1, -1), nodes, (1, 1, 1), nodes, (-1, -1, -1) 1, nodes, (-1, -1, 1)] Length = Lane (end) -Len (start)  

This is an extreme example (to be in depth to 4 0), and 4096 will produce different values, although 99 % Time This will not be something bigger in this way, so the performance should not be taken too much. In the case of

Example of starting and ending values, I do not need the values ??of each length, they all require maximum length, such as -

 < Code> [nodes, (1, 1, 1)), nodes, (-1, -1, -1), nodes, (-1, -1, -1), nodes (-1, -1, -1), nodes, (-1, -1, -1), nodes, (-1, -1), -1), nodes, (-1 , -1, 1), nodes, (-1, -1, -1), nodes, (-1, -1, -1), nodes, (-1, -1, -1) )] [Nodes, (1, 1, 1), nodes, (-1, -1, -1), nodes, (-1, 1, -1), nodes, (- 1, -1, -1), nodes, (-1, -1, -1), nodes, (-1, -1, -1)] # 4002 value later [Nodes, (1, 1, 1), nodes, (-1, -1, -1), nodes, (1, 1, 1), nodes, (1, 1, 1 ), Nodes, (1, 1, 1), nodes, (1, 1, 1)]  

I had an attempt but I realized it was not really recursive Here, it is anyway -

  newThing = {} for the range I (length / 2): Try: # Set it to the previous level so that you can add new text [I ] = Excluding NewType [i-1]: # Close New Ting [I] = {} For Category (Lennon (Structure)): newThing [i] [j] = start # J Add structure structure to each for new structure (new structure): [new] 

Everyone really needs to have every list during the runtime, so if it is found on one platform where it can print all the combinations from within the loop, which would be great, because memory is not stored at all

Since there is no answer, I thought that The easiest way to get around will be a recurring event, and be lucky. It will continue to build lists until they hit the maximum length and return them all once.

  def recursiveList (current input, combination, length): newInputList = [] for input in currentInput: if lane (input) & lt; Combination: To combine in combination: newInputList + = recursiveList ([Input + [input [0], combination]], combination, length) Other: newInputList.append (Input) back to new InputList  
< P> Use the values ??posted in the question, recursiveList ([start], structure, len (end)) 4096 will return the correct value

It seems very fast Also, there are time outcome results -

64 lists: 0.0000057 seconds / 512 list: 0.00048 seconds / 4096 list: 0.004 seconds = 32768 list: 0.032 seconds

< / Html>

go to link download
download
alternative link download

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.