<div dir="ltr">There are many ways.  Here is ONE of them<div><br></div><div><div>>>> def squish(a_list, b_list):</div><div><span class="" style="white-space:pre"> </span>res = []</div><div><span class="" style="white-space:pre">   </span>matching = False</div>
<div><span class="" style="white-space:pre">    </span>for idx, i in enumerate(a_list):</div><div><span class="" style="white-space:pre">           </span>if i == b_list[idx]:</div><div><span class="" style="white-space:pre">                       </span>matching = True</div>
<div><span class="" style="white-space:pre">                    </span>res.append(i)</div><div><span class="" style="white-space:pre">                      </span>continue</div><div><span class="" style="white-space:pre">           </span>if matching:  # note this does not happen unless dissimilar</div>
<div><span class="" style="white-space:pre">                    </span>res.append(i)</div><div><span class="" style="white-space:pre">                      </span>res.append(b_list[idx])</div><div><span class="" style="white-space:pre">            </span>else:</div><div>
<span class="" style="white-space:pre">                       </span>res.append(i)</div><div><span class="" style="white-space:pre">      </span>return res, matching</div><div><br></div><div>>>> while len(x):</div><div><span class="" style="white-space:pre">     </span>res, matching = squish(x[0], x[1])</div>
<div><span class="" style="white-space:pre">    </span>if matching:</div><div><span class="" style="white-space:pre">               </span>y.append(res)</div><div><span class="" style="white-space:pre">              </span>del x[0]</div><div><span class="" style="white-space:pre">           </span>del x[1]</div>
<div><span class="" style="white-space:pre">    </span>else:</div><div><span class="" style="white-space:pre">              </span>y.append(x[0])</div><div><span class="" style="white-space:pre">             </span>del x[0]</div><div><span class="" style="white-space:pre">   </span>if len(x) == 1:</div>
<div><span class="" style="white-space:pre">            </span>y.append(x[0])</div><div><span class="" style="white-space:pre">             </span>x = []</div><div><br></div><div><span class="" style="white-space:pre">            </span></div><div>>>> y</div>
<div>[['cat', 'NM123', 'NM234', 12], ['cat', 'NM234', 12]]</div></div><div><br></div><div>The problem here is ...  Definition is fuzzy.  Should that happen for every match even if lists with matching multiples even if they are not adjacent (leaving that as an exercise since the problem was not well-defined).</div>
<div><br></div><div>Michael Moore</div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Dec 4, 2013 at 11:06 PM, Vikram K <span dir="ltr"><<a href="mailto:vikthirtyfive@gmail.com" target="_blank">vikthirtyfive@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><font face="arial, sans-serif"><span style="border-collapse:collapse">Any suggestions on what i have to do to go from x to y?</span></font><div>
<font face="arial, sans-serif"><span style="border-collapse:collapse"><br>
</span></font></div><div><font face="arial, sans-serif"><span style="border-collapse:collapse"><div>>>> x = [['cat','NM123',12],['cat','NM234',12], ['dog', 'NM56',65]]</div>

<div>>>> x</div><div>[['cat', 'NM123', 12], ['cat', 'NM234', 12], ['dog', 'NM56', 65]]</div><div>>>> y = []</div><div>>>> y = [['cat','NM123, NM234', 12], ['dog', 'NM56', 65]]</div>

<div>>>> </div><div><br></div><div>Regards</div><div>Vik</div></span></font></div></div>
<br>_______________________________________________<br>
Baypiggies mailing list<br>
<a href="mailto:Baypiggies@python.org">Baypiggies@python.org</a><br>
To change your subscription options or unsubscribe:<br>
<a href="https://mail.python.org/mailman/listinfo/baypiggies" target="_blank">https://mail.python.org/mailman/listinfo/baypiggies</a><br></blockquote></div><br></div>