|
|
|
|
|
by cpdean
1175 days ago
|
|
I'm a huge fan of awk but the "Python vs awk" page this links to [1] shows python code that's almost deliberately atrocious. Take this function the author wrote for converting a list of integers (or strings) into floats def ints2float(integerlist):
for n in range(0,len(integerlist)):
integerlist[n]=float(integerlist[n])
return integerlist
Using `range(0,len(integerlist))` immediately betrays how the author doesn't understand python. The first arg in `range` is entirely redundant. Mutating the input list like this is also just bad design. If someone has used python for longer than a month, you'd write this with just `[float(i) for i in integerlist]`.Further down in the function `format_captured` you see this attempt at obfuscation: freqs=ints2float(filter(None,captured[n].split(' '))[2:5])
Why bother with a `filter`? Who hurt you? freqs = ints2float(captured[n].split(' ')[2:5])
That said, the author's implementation in awk does look pretty clean. I'm just peeved that they straw-manned the other language.[1] https://pmitev.github.io/to-awk-or-not/Python_vs_awk/ |
|
That code was so bad I felt I had to step in too, I used chatGPT to simplify it a bit but it also introduced some errors, so I found what appears to be an input file to test it on [1]. The only difference with the awk program is that it uses spaces while the original python program used tabs.
[1] https://dornshuld.chemistry.msstate.edu/comp-chem/first-gaus...