In Python 2:
>>> list_a = [1, 2, 3, 4]
>>> list_b = [5, 6, 7, 8]
>>> zip(list_a, list_b)
[(1, 5), (2, 6), (3, 7), (4, 8)]
In Python 3:
>>> list_a = [1, 2, 3, 4]
>>> list_b = [5, 6, 7, 8]
>>> list(zip(list_a, list_b))
[(1, 5), (2, 6), (3, 7), (4, 8)]
More Related Contents:
- How can I add tuples in a list? [closed]
- how to unpack a tuple in this form (‘abc’, [20, 20])? [closed]
- What’s the difference between lists and tuples?
- How to extract the n-th elements from a list of tuples
- Are tuples more efficient than lists in Python?
- List vs tuple, when to use each? [duplicate]
- a mutable type inside an immutable container
- How to unzip a list of tuples into individual lists? [duplicate]
- Append to a list defined in a tuple – is it a bug? [duplicate]
- merging Python dictionaries
- Subtracting 2 lists in Python
- List of tuples to dictionary [duplicate]
- Merging dictionary value lists in python
- What is the inverse function of zip in python? [duplicate]
- How to find the maximum value in a list of tuples? [duplicate]
- Converting a list of tuples into a dict
- Find an element in a list of tuples
- Why is tuple faster than list in Python?
- How to merge multiple lists into one list in python? [duplicate]
- How to convert list of tuples to multiple lists?
- What’s the difference between lists enclosed by square brackets and parentheses in Python?
- Convert a columns of string to list in pandas
- How to flatten a tuple in python
- How do I merge multiple lists into one list? [duplicate]
- Does Python have an immutable list?
- Swap values in a tuple/list inside a list in python?
- python – get list of tuples first index?
- How to zip two lists of lists
- If in Python I put a list inside a tuple, can I safely change the contents of that list? [duplicate]
- In what case would I use a tuple as a dictionary key? [closed]