How to extend an existing JavaScript array with another array, without creating a new array

The .push method can take multiple arguments. You can use the spread operator to pass all the elements of the second array as arguments to .push: >>> a.push(…b) If your browser does not support ECMAScript 6, you can use .apply instead: >>> a.push.apply(a, b) Or perhaps, if you think it’s clearer: >>> Array.prototype.push.apply(a,b) Please note … Read more

How do I concatenate text files in Python?

This should do it For large files: filenames = [‘file1.txt’, ‘file2.txt’, …] with open(‘path/to/output/file’, ‘w’) as outfile: for fname in filenames: with open(fname) as infile: for line in infile: outfile.write(line) For small files: filenames = [‘file1.txt’, ‘file2.txt’, …] with open(‘path/to/output/file’, ‘w’) as outfile: for fname in filenames: with open(fname) as infile: outfile.write(infile.read()) … and another … Read more

How can I concatenate twice with the C preprocessor and expand a macro as in “arg ## _ ## MACRO”?

Standard C Preprocessor $ cat xx.c #define VARIABLE 3 #define PASTER(x,y) x ## _ ## y #define EVALUATOR(x,y) PASTER(x,y) #define NAME(fun) EVALUATOR(fun, VARIABLE) extern void NAME(mine)(char *x); $ gcc -E xx.c # 1 “xx.c” # 1 “<built-in>” # 1 “<command-line>” # 1 “xx.c” extern void mine_3(char *x); $ Two levels of indirection In a comment … Read more

Why does concatenation of DataFrames get exponentially slower?

Never call DataFrame.append or pd.concat inside a for-loop. It leads to quadratic copying. pd.concat returns a new DataFrame. Space has to be allocated for the new DataFrame, and data from the old DataFrames have to be copied into the new DataFrame. Consider the amount of copying required by this line inside the for-loop (assuming each … Read more