## Fix Python – What is the inverse function of zip in python? [duplicate]

Closed 9 years ago.

Possible Duplicate:
A Transpose/Unzip Function in Python

I’ve used the zip() function from the numpy library to sort tuples and now I have a list containing all the tuples. I had since modified that list and now I would like to r….

## Fix Python – How does tuple comparison work in Python?

I have been reading the Core Python programming book, and the author shows an example like:
(4, 5) < (3, 5) # Equals false So, I'm wondering, how/why does it equal false? How does python compare these two tuples? Btw, it's not explained in the book. ....

## Fix Python – How to convert comma-delimited string to list in Python?

Given a string that is a sequence of several values separated by a commma:
mStr = ‘A,B,C,D,E’

How do I convert the string to a list?
mList = [‘A’, ‘B’, ‘C’, ‘D’, ‘E’]

….

## Fix Python – Unpacking a list / tuple of pairs into two lists / tuples

Possible Duplicate:
A Transpose/Unzip Function in Python

I have a list that looks like this:
list = ((‘1′,’a’),(‘2′,’b’),(‘3′,’c’),(‘4′,’d’))

I want to separate the list in 2 lists.
list1 = (‘1′,’2′,’3′,’4’)
list2 = (‘a’,’b’,’c’,’d’)

I can do it for example with:
list1 = []
list2 = []
for i in list:
list1.append(i)
list2.append(i….

## Fix Python – How to unzip a list of tuples into individual lists? [duplicate]

Closed 9 years ago.

Possible Duplicate:
A Transpose/Unzip Function in Python

I have a list of tuples, where I want to unzip this list into two independent lists. I’m looking for some standardized operation in Python.
>>> l = [(1,2), (3,4), (8,9)]….

## Fix Python – Are tuples more efficient than lists in Python?

Is there any performance difference between tuples and lists when it comes to instantiation and retrieval of elements?
….

## Fix Python – How to merge lists into a list of tuples?

What is the Pythonic approach to achieve the following?
# Original lists:

list_a = [1, 2, 3, 4]
list_b = [5, 6, 7, 8]

# List of tuples from ‘list_a’ and ‘list_b’:

list_c = [(1,5), (2,6), (3,7), (4,8)]

Each member of list_c is a tuple, whose first member is from list_a and the second is from list_b.
….

## Fix Python – Ignore python multiple return value

Say I have a Python function that returns multiple values in a tuple:
def func():
return 1, 2

Is there a nice way to ignore one of the results rather than just assigning to a temporary variable? Say if I was only interested in the first value, is there a better way than this:
x, temp = func()

….

## Fix Python – Why is there no tuple comprehension in Python?

As we all know, there’s list comprehension, like
[i for i in [1, 2, 3, 4]]

and there is dictionary comprehension, like
{i:j for i, j in {1: ‘a’, 2: ‘b’}.items()}

but
(i for i in (1, 2, 3))

will end up in a generator, not a tuple comprehension. Why is that?
My guess is that a tuple is immutable, but this does not seem to be the answer.
….

## Fix Python – Expanding tuples into arguments

Is there a way to expand a Python tuple into a function – as actual parameters?
For example, here expand() does the magic:
some_tuple = (1, “foo”, “bar”)

def myfun(number, str1, str2):
return (number * 2, str1 + str2, str2 + str1)

myfun(expand(some_tuple)) # (2, “foobar”, “barfoo”)

I know one could define myfun as myfun((a, b, c)), but of c….