I think I really dislike Python

Ruby:

> irb
irb(main):001:0> a = [1,2,3]
=> [1, 2, 3]
irb(main):002:0> a[10] = 20
=> 20
irb(main):003:0> a
=> [1, 2, 3, nil, nil, nil, nil, nil, nil, nil, 20]


Perl:

> perl
@a = (1,2,3);
$a[10] = 20;
use Data::Dumper;
print Dumper(@a);
$VAR1 = 1;
$VAR2 = 2;
$VAR3 = 3;
$VAR4 = undef;
$VAR5 = undef;
$VAR6 = undef;
$VAR7 = undef;
$VAR8 = undef;
$VAR9 = undef;
$VAR10 = undef;
$VAR11 = 20;


Python:

> python
>>> a = [1,2,3]
>>> a[10] = 20
Traceback (most recent call last):
  File "", line 1, in ?
IndexError: list assignment index out of range
>>> a
[1, 2, 3]

4 thoughts on “I think I really dislike Python

  1. That’s exactly why I like python.
    It takes all the black magic out of programming. But if you insist:

    class RubyStyleList(list):
        def __setitem__(self, idx, val):
            if len(self) < idx:
                self.extend( [None]*(idx-len(self)) )
            return super(RubyStyleList, self).__setitem__(idx, val)
    
    >>> l = RubyStyleList([1,2,3])
    >>> l
    [1, 2, 3]
    >>> l[10]=99
    >>> l
    [1, 2, 3, None, None, None, None, None, None, None, 99]

  2. Actually, it has been more than a year now that I work with Python everyday at my day job. I still dislike it, but started to understand the verbosity and torturing of programmers that it brings as a necessary evil.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>