I find it interesting how things can be expressed in terms of tuples in python
>>> list(( dict( ( ("a",1), ("b", "abc"), ("c", list( (1,2,3) ) ) ) ), ))
[{'a': 1, 'c': [1, 2, 3], 'b': 'abc'}]
reminds me of cons a little
so now if I break this further I can get:
>>> ( list, ( dict, ( list, ( ("a",1), ("b", "abc"), ("c", list, (1,2,3)) ) ) ) )
(<type 'list'>, (<type 'dict'>, (<type 'list'>, (('a', 1), ('b', 'abc'), ('c', <type 'list'>, (1, 2, 3))))))
and then rebuild this with possibly some sort of a reduce, such as
>>> reduce(lambda acc, x: acc +[x], (1,2,3), [])
[1, 2, 3]
I am not looking to break new ground, just simply document some of the things that I found to be useful in everyday work. Sometimes I spend a considerable amount of time to find a solution for a problem that seemed silly and simple. I hope that some of my posts will save you some time.
Showing posts with label cons. Show all posts
Showing posts with label cons. Show all posts
Thursday, June 20, 2013
Subscribe to:
Posts (Atom)