News for hackers. Stuff that matters.
Re:Perl 6 Optimism by 1024core on Tuesday January 23, 2018 @12:09PM (#16215126)
As a former Perl programmer, dabbling in Python, I keep getting reminded how awesome Perl is.

For example: I'm collecting some stats indexed by (small) ints. In Perl, I'd just say

    $collection[$index] = $stat;
Try that in Python when $index is not received in order.

Edit: Fixed typo; meant "$stat" and not "%stat"

Re:Perl 6 Optimism by kstrauser on Tuesday January 23, 2018 @12:24PM (#16215279)
In Python:

    dict[index] = stat
...works much the same.
Re:Perl 6 Optimism by arunix on Tuesday January 23, 2018 @01:02PM (#16215665)
The Python version blows up if the slot isn't already populated. The Perl version works in either case (there is a typo in the Perl code though).
Re:Perl 6 Optimism by amyjess on Tuesday January 23, 2018 @01:10PM (#16215750)
Only if you're using a list, not a dict. I just tried it in the REPL:

    >>> foo = {}
    >>> foo[3] = 72
    >>> foo[64] = 80
    >>> foo
    {3: 72, 64: 80}
Re:Perl 6 Optimism by arunix on Thursday January 25, 2018 @08:27AM (#16230591)
The difference is more dramatic once you have two or more dimensions:

    >>> foo = {}
    >>> foo[3][4] = 42
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    KeyError: 3
Compared to:

      DB<1> $foo{3}{4} = 42

      DB<2> x \%foo
    0  HASH(0x7f9f4315c940)
       3 => HASH(0x7f9f432bb148)
          4 => 42
Re:Perl 6 Optimism by pseudalopex on Monday January 29, 2018 @07:34AM (#16257095)

    tree = lambda: collections.defaultdict(tree)
    foo = tree()
    foo[3][4] = 42
Re:Perl 6 Optimism by occams_chainsaw on Tuesday January 23, 2018 @12:28PM (#16215329)
I don't think I'd want or need to try that...
Re:Perl 6 Optimism by zyxzkz on Tuesday January 23, 2018 @01:48PM (#16216193)

     \%stat;