F
falcon
Hi All,
I am fairly new to Python (less than a week). My goal is to write a
small prototype of a database. Rather than build it using the typical
method where one provides selection, projection, aggregation, union,
intersection, etc. functions, I would like to do it in a more
'functional' style (executing a database query by using map, reduce,
filter, etc. I am curious what the best way is to work with a list of
tuples. For example, if I have the following list:
[('a',1),('a',1),('a',3),('b',1),('b',2),('c',2),('c',3),('c',4)]
how do I apply a map to each item in each tuple in the list? What if I
want to filter based on both elements (the number AND the letter)?
The most obvious solution is just to provide a function or a lambda
expression whcih does what I want. However, since this is, eventually,
going to be a database, the user will decide at run time what functions
and operations should be run on a 'table' (really a list of tuples) ...
and the structure of the 'table' will obviously not be known until
run-time.
I didn't find any examples of using idioms from functional programming
beyond basic explanation of reduce and map (I have a couple of Haskell
and ML books, but I know those languages even less than Python).
I hope you understand the problem. Thanks in advance.
I am fairly new to Python (less than a week). My goal is to write a
small prototype of a database. Rather than build it using the typical
method where one provides selection, projection, aggregation, union,
intersection, etc. functions, I would like to do it in a more
'functional' style (executing a database query by using map, reduce,
filter, etc. I am curious what the best way is to work with a list of
tuples. For example, if I have the following list:
[('a',1),('a',1),('a',3),('b',1),('b',2),('c',2),('c',3),('c',4)]
how do I apply a map to each item in each tuple in the list? What if I
want to filter based on both elements (the number AND the letter)?
The most obvious solution is just to provide a function or a lambda
expression whcih does what I want. However, since this is, eventually,
going to be a database, the user will decide at run time what functions
and operations should be run on a 'table' (really a list of tuples) ...
and the structure of the 'table' will obviously not be known until
run-time.
I didn't find any examples of using idioms from functional programming
beyond basic explanation of reduce and map (I have a couple of Haskell
and ML books, but I know those languages even less than Python).
I hope you understand the problem. Thanks in advance.