[Tutor] How to create a key-value pairs with alternative elements
in a list ... please help.
kumar s
ps_python at yahoo.com
Wed Jan 12 22:26:15 CET 2005
Thanks for this trick.
Can I call this as category thermo-NUKE of list
functions.
-K
--- Jeff Shannon <jeff at ccvcorp.com> wrote:
> kumar s wrote:
>
> > Problem:
> > How do i capture every alternative element in list
> a:
> >
> > I am unable to pump the a,b, and c into keys list
> > and apple, boy,cat into vals list.
>
> In a sufficiently recent version of Python, you
> should be able to use
> an extended slice with a stride --
>
> keys = a[::2]
> vals = a[1::2]
>
> (Note that this is untested, as I don't have a
> recent version of
> Python handy at the moment; I'm on 2.2 here, which
> doesn't have
> extended slices.)
>
> Jeff Shannon
> Technician/Programmer
> Credit International
>
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
More information about the Tutor
mailing list