Abhishek Tiwari wrote:
>  
> *Ans. 1*
>  
> values, items = list(zip(*sorted(zip(values,items), reverse=True)))
>  
> *Ans. 2*
> new_values = sorted(values, reverse=True)
> new_items = [items[x] for x in map(values.index,new_values)]
>  
> I would like to know which method is better and why?

The first one is better because the second one has a bug. ;-)

Because of the way the second one uses values.index, it assumes there is
a unique mapping between items and values.  When a duplicate integer
appears in values, the second solution returns the wrong answer.

-Jeff
_______________________________________________
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers

Reply via email to