Do this as a list comprehension?
Lie.1296 at gmail.com
Wed Jun 11 01:09:29 CEST 2008
On Jun 8, 11:11 pm, Mensanator <mensana... at aol.com> wrote:
> 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?
Yep, but it's not the sole controller of the length of a list. There
are other things that might control the length of the list like del,
> > 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?
What I meant is in some cases (not all) the list might semantically be
nonsense if it is of different length (i.e. it have fixed length).
> > 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?
I think it is up to the programmer to decide whether special case is
enough or a general case is necessary.
More information about the Python-list