Python one-liner (converting perl to pyp) -


i wondering if possible make one-liner pyp has same functionality this.

perl -l -a -f',' -p -e'if ($. > 1) { $f[6] %= 12; $f[7] %= 12;$_ = join(q{,}, @f[6,7]) }' 

this takes in comma separated list of numbers 8 numbers per line , outputs in same format except last 2 numbers in each line reduced modulo 12. outputs first line (the header line) verbatim first.

i have quite lot of these obscure perl one-liners , in first instance translate them python.

for record, i'm not sure approve. writing code horizontally doesn't seem me better writing vertically, , -- in friendly way -- i'm little sceptical offers many advantages in practice might seem. 1 of joys of python no longer have worry writing golfscript.

that said, how about:

pyp "mm | p if n==0 else (p[:-2] + [(int(x)%12) x in p[-2:]]) | mm" 

which produces:

localhost-2:coding $ cat exam.pyp  a,b,c,d,e,f,g,h 11,22,33,44,55,66,77,88 12,23,34,45,56,67,78,89 13,24,35,46,57,68,79,80 localhost-2:coding $ cat exam.pyp | pyp "mm | p if n==0 else (p[:-2] + [(int(x)%12) x in p[-2:]]) | mm" a,b,c,d,e,f,g,h 11,22,33,44,55,66,5,4 12,23,34,45,56,67,6,5 13,24,35,46,57,68,7,8 

[disclaimer: first-ever pyp program, downloaded ten minutes ago.]


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -