[Tutor] help with slice
bgailer at alum.rpi.edu
Wed Mar 5 01:13:44 CET 2008
> Could someone please explain 'slices' also for dictionaries?
> basically, I'd like to know how you would call every 3rd element in a list
> of lists...
> My logic says: ThirdElems=List[:]
> Which to me reads, for every item in List (which are lists), return the
> third item.
That is wishful reading. No basis in reality. List[:] gives you a
shallow copy of List.  then refers to the 3rd element of that copy.
Try: [sublist for sublist in List]
919-636-4239 Chapel Hill, NC
More information about the Tutor