[Tutor] is the the two style of writting the same?

Prasad, Ramit ramit.prasad at jpmorgan.com.dmarc.invalid
Tue Aug 20 21:37:30 CEST 2013


tan Sikonai wrote:
> 
> ?

You should wait at least 24 hours as many people in this mailing list
are around the world and may not see this immediately.

> 
> 2013/8/20 sikonai sikonai <tanjyunda at gmail.com>
> >>> list=[1,2,3,4,5,6,7,8,9]
> >>> list[9:0:-2]
> [9, 7, 5, 3]
> >>> list[10:0:-2]
> [9, 7, 5, 3]
> 
> I want to know whether they have some difference.

You should try and avoid using built-in names like "list" as this shadows 
list function.

Yes, there is a difference. Python slices ignore out of range elements so 
this becomes the last element and elements with a -2 step (meaning traverse 
the list in reverse and select every other element) until you get to the
0th slot.


>>> list[100:0:-2]
[9, 7, 5, 3]


~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