Combine two lists in a pythonic way
Question: I have no clue how to search for this, however, I cannot find an obvious
solution for my pythonic problem. I would like to combine two lists (one is a
manipulated one of the other) and permute them by keeping the length of the
lists constant.

An example:

    
    
    a = ['A','B','C','D']
    b = ['a','b','c','d']
    
    combined = [['a','B','C','D'], ['A','b','C','D'], ..., ['a','b','c','d']]
    

And then I can permute them using itertools. However, the first step is for me
not easy to manage. I don't want nested for-loops and Co.


Answer: Using [`zip`](https://docs.python.org/3/library/functions.html#zip),
[`itertools.product`](https://docs.python.org/3/library/itertools.html#itertools.product)
and [list
comprehension](https://docs.python.org/3/tutorial/datastructures.html#list-
comprehensions):

    
    
    >>> import itertools
    >>> a = ['A','B','C','D']
    >>> b = ['a','b','c','d']  # [x.lower() for x in a]
    >>> [list(x) for x in itertools.product(*zip(a, b))]
    [['A', 'B', 'C', 'D'], ['A', 'B', 'C', 'd'], ['A', 'B', 'c', 'D'],
     ['A', 'B', 'c', 'd'], ['A', 'b', 'C', 'D'], ['A', 'b', 'C', 'd'],
     ['A', 'b', 'c', 'D'], ['A', 'b', 'c', 'd'], ['a', 'B', 'C', 'D'],
     ['a', 'B', 'C', 'd'], ['a', 'B', 'c', 'D'], ['a', 'B', 'c', 'd'],
     ['a', 'b', 'C', 'D'], ['a', 'b', 'C', 'd'], ['a', 'b', 'c', 'D'],
     ['a', 'b', 'c', 'd']]
    

