"washakie" <[EMAIL PROTECTED]> wrote > Could someone please explain 'slices' also for dictionaries?
So far as I know slices don;t work for dictionaries directly - dictionaries don't have the concept of order. However you could get a list of keys and apply a slice to that, although I'm not sure how it would ever be useful. > basically, I'd like to know how you would call every 3rd element in > a list > of lists... > > My logic says: ThirdElems=List[:][2] > Which to me reads, for every item in List (which are lists), return > the > third item.but this doesn't work. This actually says take a copy of the list and give me the 3rd element of that copy. You need to use a list comprehension: thirds = [sublist[2] for sublist in myList] HTH, -- Alan Gauld Author of the Learn to Program web site Temorarily at: http://uk.geocities.com/[EMAIL PROTECTED]/ Normally: http://www.freenetpages.co.uk/hp/alan.gauld _______________________________________________ Tutor maillist - [email protected] http://mail.python.org/mailman/listinfo/tutor
