Do this as a list comprehension?

Mensanator mensanator at aol.com
Sun Jun 8 12:11:56 EDT 2008


On Jun 8, 4:04 am, Lie <Lie.1... at gmail.com> wrote:
> On Jun 8, 8:56 am, Mensanator <mensana... at aol.com> wrote:
>
>
>
>
>
> > On Jun 7, 8:22�pm, John Salerno <johnj... at gmailNOSPAM.com> wrote:
>
> > > Mensanator wrote:
> > > > What I DID say was that how the builtins actually
> > > > work should be understood and it APPEARED that the
> > > > OP didn't understand that. Maybe he understood that
> > > > all along but his example betrayed no evidence of
> > > > that understanding.
>
> > > Well, the truth is that I know zip truncates to the shorter of the two
> > > arguments,
>
> > Ok, sorry I thought otherwise.
>
> > > and also in my case the two arguments would always be the
> > > same length.
>
> > Yes, because you're controlling the source code.
> > But since lists are mutable, source code literals
> > don't always control the length of the list.
>
> Since when source code literals ever control the length of a list?

Isn't score_costs = [0, 1, 1, 1, 1, 1, 1, 2, 2, 3, 3]
considered a literal?

> What controls the length of the list is the semantic meaning of the
> list,

Wha do you mean by that? The list contains 11 objects.
How could the length be any different?

> in some cases it just makes no sense that the list would ever
> have different length.

And in such case there won't be any problem, will there?

Is that a good habit to teach a newbie? To write
code that only works for special cases?

>
> (snip)- Hide quoted text -
>
> - Show quoted text -




More information about the Python-list mailing list