You’re looking for itertools.product if you’re on (at least) Python 2.6.
>>> import itertools
>>> a=[1,2,3]
>>> b=[4,5,6]
>>> itertools.product(a,b)
<itertools.product object at 0x10049b870>
>>> list(itertools.product(a,b))
[(1, 4), (1, 5), (1, 6), (2, 4), (2, 5), (2, 6), (3, 4), (3, 5), (3, 6)]
More Related Contents:
- How to make a dict from n’th indices of tuples in list
- How do I concatenate items in a list to a single string?
- Why does this iterative list-growing code give IndexError: list assignment index out of range?
- Why does this code for initializing a list of lists apparently link the lists together? [duplicate]
- Slicing a list in Python without generating a copy
- Python list doesn’t reflect variable change
- Removing item from list causes the list to become NoneType
- Why is [] faster than list()?
- How can I multiply all items in a list together with Python?
- How to unzip a list of tuples into individual lists? [duplicate]
- Remove trailing newline from the elements of a string list
- How to loop through all but the last item of a list?
- Writing a list to a file with Python, with newlines
- How can I convert each item in the list to string, for the purpose of joining them? [duplicate]
- How can I initialize a dictionary of distinct empty lists in Python?
- Take the content of a list and append it to another list
- Extract elements of list at odd positions
- How to find the maximum value in a list of tuples? [duplicate]
- In Python, why is list[] automatically global?
- How to read an array of integers from single line of input in python3
- Why do I get “List index out of range” when trying to add consecutive numbers in a list using “for i in list”? [duplicate]
- List to array conversion to use ravel() function
- convert a string which is a list into a proper list python
- Unexpected IndexError while removing list items [duplicate]
- How to remove item from a python list in a loop? [duplicate]
- How do I sort this list in Python, if my date is in a String?
- Convert all strings in a list to integers
- “TypeError: ‘type’ object is not subscriptable” in a function signature
- Python Sort One List According to Another List
- Nested lambda statements when sorting lists