<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
On 2:59 PM, smith jack wrote:
<blockquote
cite="mid:%3CCAN1Fwxcdtt0u_TT=civMes1hA2qvfkH2YckES7B7qRE++DXzJQ@mail.gmail.com%3E"
type="cite">
<pre wrap="">if a list L is composed with tuple consists of two elements, that is
L = [(a1, b1), (a2, b2) ... (an, bn)]
is there any simple way to divide this list into two separate lists , such that
L1 = [a1, a2... an]
L2=[b1,b2 ... bn]
i do not want to use loop, any methods to make this done?
</pre>
</blockquote>
<br>
The official Python documentation [1] notes that "<a title="zip"
class="reference internal"
href="http://docs.python.org/library/functions.html#zip"><tt
class="xref docutils literal"><span class="pre">zip()</span></tt></a>
in conjunction with the <tt class="docutils literal"><span
class="pre">*</span></tt> operator can be used to unzip a
list". Ex:<br>
<br>
>>> L = [ (1,'a'), (2,'b'), (3,'c'), (4,'d') ]<br>
>>> zip(*L)<br>
[(1, 2, 3, 4), ('a', 'b', 'c', 'd')]<br>
<br>
<br>
HTH,<br>
John<br>
<br>
[1] <a class="moz-txt-link-freetext" href="http://docs.python.org/library/functions.html">http://docs.python.org/library/functions.html</a><br>
<br>
</body>
</html>