Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The process to generate a list consisting of two elements from one list for every element in another list is called cartesian product or cross product.

Here are the steps:

  1. Create two lists: List A and List B.

  2. Iterate through every element in List A.

  3. For each element in List A, iterate through every element in List B.

  4. For each element in List B, create a new list that contains the element from List A and the element from List B.

  5. Add the new list to a result list.

  6. After iterating through all elements in List A, the result list will contain every possible combination of two elements from List B for each element in List A.

Example:

List A: [1, 2, 3]

List B: [4, 5]

Result list: [[1, 4], [1, 5], [2, 4], [2, 5], [3, 4], [3, 5]]