[Tutor] A mergesort
Prasad, Ramit
ramit.prasad at jpmorgan.com.dmarc.invalid
Tue Sep 3 17:56:28 CEST 2013
D.V.N.Sarma wrote:
[snip recursive merge sort algorithm]
> Especially the statement
>
> v = (a[0] < b[0] and a or b).pop(0)
>
> gives a.pop(0), if a[0] < b[0] otherwise b.pop(0).
I believe this idiom was used before the ternary if statements were
introduced (in 2.5 I believe). In modern Python you could do an
ternary if which is more explicit and clearer in my mind.
v = a.pop(0) if a[0]<b[0] else b.pop(0)
>
> We have to look at the statement as
>
> v = ((a[0] < b[0] and a) or b).pop(0)
v = (a if a[0]< b[0] else b).pop(0)
>
>
> regards,
> Sarma.
~Ramit
This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email.
More information about the Tutor
mailing list