Advertisement
Guest User

Untitled

a guest
May 20th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. '''
  2. # this psuedocode was helpful in determining the output
  3. # for the main cartesian product function
  4. ---
  5. # old_collection: [[1, 2, 3], [a, b, c]]
  6. # new_collection: [[]]
  7. # for old_group in old_collection:
  8. # old_group = [1,2,3]
  9. # create empty new_collection_temp array
  10. # this will be used to store data from this next loop
  11. # for new_group in new_collection:
  12. # new_group = []
  13. # run convert_group with old_group and new_group
  14. # returns [[1],[2],[3]]
  15. # concatinates returned value with temp_new_collection array
  16. # temp_new_collection is now [[1],[2],[3]]
  17. # exit inner loop
  18. # set new_collection equal to temp_new_collection
  19. # we can't modify a list during a loop so we do it here
  20. # new_collection now is [[1],[2],[3]]
  21. # old_group = [a,b,c]
  22. # create empty new_collection_temp array
  23. # this will be used to store data from this next loop
  24. # for new_group in new_collection:
  25. # new_group = [1]
  26. # run convert_group with old_group and new_group
  27. # returns [[1,a],[1,b],[1,c]]
  28. # concatinates returned value with temp_new_collection array
  29. # temp_new_collection is now [[1,a],[1,b],[1,c]]
  30. # new_group = [2]
  31. # run convert_group with old_group and new_group
  32. # returns [[2,a],[2,b],[2,c]]
  33. # concatinates returned value with temp_new_collection array
  34. # temp_new_collection is now [[1,a],[1,b],[1,c],[2,a],[2,b],[2,c]]
  35. # new_group = [3]
  36. # run convert_group with old_group and new_group
  37. # returns [[3,a],[3,b],[3,c]]
  38. # concatinates returned value with temp_new_collection array
  39. # temp_new_collection is now [[1,a],[1,b],[1,c],[2,a],[2,b],[2,c],[3,a],[3,b],[3,c]]
  40. # exit inner loop
  41. # set new_collection equal to temp_new_collection
  42. # we can't modify a list during a loop so we do it here
  43. # new_collection now is [[1,a],[1,b],[1,c],[2,a],[2,b],[2,c],[3,a],[3,b],[3,c]]
  44. # exit outter loop
  45. # the loop exponentially increases in size as we go
  46. # this means it is a heavy performance factor
  47. ===
  48. # this psuedocode was helpful in determining the output
  49. # it was originally going to be a helper function
  50. # but was integrated into one piece later:
  51. ---
  52. def convert_group(old_group, new_group)
  53. # input: [x, y, z], [a, 1]
  54. # output: [[a, 1, x], [a, 1, y], [a, 1, z]]
  55. # create an empty base array.
  56. # for each item in the given old group:
  57. # create a new array equal to the given new group.
  58. # append the item to the new array.
  59. # append this new array to the base array.
  60. # return the filled base array.
  61. '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement