[Tutor] help with slice
andreas at kostyrka.org
Tue Mar 4 23:28:53 CET 2008
What you probably want is:
[elem_list for elem_list in List]
If you are not sure that the list have at least three elements, you can
use something like this:
[(elem_list + [None, None, None]) for elem_list in List]
Which will use None as a default value.
Am Dienstag, den 04.03.2008, 14:03 -0800 schrieb washakie:
> 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.
> but this doesn't work.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 189 bytes
Desc: Dies ist ein digital signierter Nachrichtenteil
Url : http://mail.python.org/pipermail/tutor/attachments/20080304/79d467ce/attachment.pgp
More information about the Tutor