<div class="gmail_quote">
<div><font color="#990000"><strong>Question :</strong></font></div>
<div>The first list contains some items, and the second list contains their value (higher is better).</div>
<div> </div>
<div>items = [apple, car, town, phone] </div>
<div>values = [5, 2, 7, 1] </div>
<div> </div>
<div>Show how to sort the 'items' list based on the 'values' list so that you end up with the following two lists:</div>
<div> </div>
<div>items = [town, apple, car, phone] </div>
<div>values = [7, 5, 2, 1] </div>
<div> </div>
<div><font color="#000099"><strong>Ans. 1</strong></font> </div>
<div> </div>
<div>values, items = list(zip(*sorted(zip(values,items), reverse=True)))</div>
<div> </div>
<div><font color="#000099"><strong>Ans. 2</strong></font> </div>
<div>new_values = sorted(values, reverse=True)</div>
<div>new_items = [items[x] for x in map(values.index,new_values)]</div>
<div> </div>
<div> </div>
<div><font color="#ff0000">I would like to know which method is better and why?</font> </div>
<div> </div>
<div> </div>
<div>-- </div>
<div>With Regards,</div>
<div>Abhishek Tiwari<font color="#888888"></font></div></div>