[Tutor] list as a first class citizen in python? [language comparisons!]

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Wed, 26 Dec 2001 00:29:59 -0800 (PST)


> But to get the same thing to work in Perl, we have to think twice.  A
> first attempt:
> 
> ###
> ## test.pl.
> sub buggy_myzip {
>     my (@l1, @l2) = @_;
>     my @results;
>     for my $i (0..scalar(@l1)) {
                    ^^^^^^^^^^

Yikes.  This is buggy for another reason.  Python's range() function is
exclusive: it goes up to, but doesn't include the right endpoint:

###
>>> range(0, 10)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
###



However, Perl's equivlant expression does include that right endpoint.  
Sorry, I forgot!  This line should have been:

### Perl
      for my $i (0..#@l1)) {
###