On 2023-11-07, Stefan Ram <r...@zedat.fu-berlin.de> wrote: > I read this in a shell newsgroup: > > perl -anE '$s += $F[1]; END {say $s}' in > > , so I wrote > > py -c "import sys; print(sum(int(F.split()[1])for F in sys.stdin))" <in > > to show that this is possible with Python too. > > But now people complain that it's longer than the Perl version. > > Do you see ways to make it shorter (beyond removing one space > after the semicolon ";")?
It's a bit of an unfair competition given that, unlike Perl, Python is not designed to be an 'awk' replacement. Having said that, you could make it a bit shorter: py -c "print(sum(int(F.split()[1])for F in open(0)))" <in -- https://mail.python.org/mailman/listinfo/python-list