Is there a better way to chose a slice of a list?

walterbyrd walterbyrd at iname.com
Tue May 19 17:38:19 EDT 2009


On May 8, 5:55 pm, John Yeung <gallium.arsen... at gmail.com> wrote:
> On May 8, 3:03 pm,walterbyrd<walterb... at iname.com> wrote:
>
> > This works, but it seems like there should be a better way.
>
> > --------------
> > week = ['sun','mon','tue','wed','thu','fri','sat']
> > for day in week[week.index('tue'):week.index('fri')]:
> >    print day
> > ---------------
>
> I think you should provide much more information, primarily why you
> want to do this.  What is the larger goal you are trying to achieve?

I am just looking for a less verbose, more elegant, way to print a
slice of a list. What is hard to understand about that? I am not sure
how enumerated types help.



More information about the Python-list mailing list