[FRPythoneers] Joining a lists of lists?

Bob Gailer ramrom at earthling.net
Thu Aug 8 14:17:51 MDT 2002


In reading the documentation for the operator module, I noticed that it 
specifies that add is for numbers and concat should be used for lists.

However the example I generated before reading the documentation works. 
Whether this might fail in some future version is unknown. To be on the 
safe side I suggest changing add to concat.

 > from operator import concat
 > a=[[1,2],[3,4]]
 > reduce(concat,a)
 > [1, 2, 3, 4]

FWIW I am also an APL programmer. One of the things that appealed to me 
when learning Python was the similarity to APL in its ability to easily 
process sequences.

In APL if one wants to reduce a sequence using add one writes "+/sequence". 
WIBNI if one could write reduce(+,sequence) in Python? (Or even better add 
symbolic operators to Python. In APL "/" is an operator that applies a 
function to a sequence (actually an array), and APL has several operators 
that apply functions in a variety of useful ways.)

Bob Gailer
mailto:ramrom at earthling.net
303 442 2625


More information about the FRPythoneers mailing list