merging lists with lists
<p>I have a list packets=[['B', 'A'], ['B', 'C'], ['A', 'D'], ['C', 'D'], ['C', 'E'], ['D', 'E'], []]. I have two for loops on the same list something like:</p>

<pre><code>for a in packets[:]:
   for b in packets[:]:
</code></pre>

<p>i.e., each time a=['B','A'] b iterates from ['B','A'] all the way to ['D','E']. This is what I want to do...if the last element of a is equal to the first element of b i.e., when a=['B','A'] and b=['A','D'] I must have ['B','A','D']. Again the last element of ['B','A','D'] is equal to the first element of ['D','E']. So, now I must have ['B','C','D','E']. Similarly, when A=['B','C'] and b=['C','E'] I must have ['B','C','E']. When A=['B','C'] and b=['C','D'] and b=['D','E'] I must have ['B','C','D','E'] and so on.</p>
