<div class="gmail_quote">
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Esmail wrote:<br><br>> items = [apple, car, town, phone]<br>> values = [5, 2, 7, 1]<br>><br>> I would like to sort the 'items' list based on the 'values' list so<br>
> that I end up with the following two list:<br>><br>> items = [town, apple, car, phone]<br>> values = [7, 5, 2, 1]</blockquote>
<div> </div>
<div>My solution, I know the 'zip' version is more elegant, this is just for fun:)</div>
<div> </div>
<div>>>> items = ['apple', 'car', 'town', 'phone']<br>>>> values = [5, 2, 7, 1]<br>>>> new_values = sorted(values, reverse = True)<br>>>> new_items = [items[x] for x in [i for i in map(values.index, new_values)]]<br>
>>> print(new_values)<br>[7, 5, 2, 1]<br>>>> print(new_items)<br>['town', 'apple', 'car', 'phone']<br>>>> </div>
<div> </div>
<div>cheers!</div>
<div> </div>
<div>tiefeng wu</div>
<div>2009-04-22</div></div>