#!/bin/python
from functools import reduce
import sys
def adder( the_dict) :
return reduce ( ( lambda x, y:
the_dict[ x] + the_dict[ y]
#sys.stdout.write(
#'***\n\n'+
#'x is not None\n'+repr(x is not None)+'\n'+
#'y is not None\n'+repr(y is not None)+'\n'+
#' x: ' + repr(x) + ' y: ' + repr(y)+'\n***\n\n')
if x is not None and y is not None else
the_dict[ x]
#sys.stdout.write(
#'***\n\n'+
#'x is not None\n'+repr(x is not None)+'\n'+
#'y is not None\n'+repr(y is not None)+'\n'+
#' x: ' + repr(x) + ' y: ' + repr(y)+'\n***\n\n')
if x is not None else
the_dict[ y]
#sys.stdout.write(
#'***\n\n'+
#'x is not None\n'+repr(x is not None)+'\n'+
#'y is not None\n'+repr(y is not None)+'\n'+
#' x: ' + repr(x) + ' y: ' + repr(y)+'\n***\n\n')
if y is not None else None )
, the_dict)
d= { 'a' :'fuck ' , 'b' :'this ' , 'c' :'pluses ' }
print ( 'd is\n ' , d)
print ( adder( d) )
IyEvYmluL3B5dGhvbgpmcm9tIGZ1bmN0b29scyBpbXBvcnQgcmVkdWNlCmltcG9ydCBzeXMKCmRlZiBhZGRlcih0aGVfZGljdCk6CglyZXR1cm4gcmVkdWNlKChsYW1iZGEgeCwgeToKCXRoZV9kaWN0W3hdICsgdGhlX2RpY3RbeV0KCSNzeXMuc3Rkb3V0LndyaXRlKAoJIycqKipcblxuJysKCSMneCBpcyBub3QgTm9uZVxuJytyZXByKHggaXMgbm90IE5vbmUpKydcbicrCgkjJ3kgaXMgbm90IE5vbmVcbicrcmVwcih5IGlzIG5vdCBOb25lKSsnXG4nKwoJIycgeDogJyArIHJlcHIoeCkgKyAnIHk6ICcgKyByZXByKHkpKydcbioqKlxuXG4nKQoJaWYgeCBpcyBub3QgTm9uZSBhbmQgeSBpcyBub3QgTm9uZSBlbHNlCgl0aGVfZGljdFt4XQoJI3N5cy5zdGRvdXQud3JpdGUoCgkjJyoqKlxuXG4nKwoJIyd4IGlzIG5vdCBOb25lXG4nK3JlcHIoeCBpcyBub3QgTm9uZSkrJ1xuJysKCSMneSBpcyBub3QgTm9uZVxuJytyZXByKHkgaXMgbm90IE5vbmUpKydcbicrCgkjJyB4OiAnICsgcmVwcih4KSArICcgeTogJyArIHJlcHIoeSkrJ1xuKioqXG5cbicpCglpZiB4IGlzIG5vdCBOb25lIGVsc2UKCXRoZV9kaWN0W3ldCgkjc3lzLnN0ZG91dC53cml0ZSgKCSMnKioqXG5cbicrCgkjJ3ggaXMgbm90IE5vbmVcbicrcmVwcih4IGlzIG5vdCBOb25lKSsnXG4nKwoJIyd5IGlzIG5vdCBOb25lXG4nK3JlcHIoeSBpcyBub3QgTm9uZSkrJ1xuJysKCSMnIHg6ICcgKyByZXByKHgpICsgJyB5OiAnICsgcmVwcih5KSsnXG4qKipcblxuJykKCWlmIHkgaXMgbm90IE5vbmUgZWxzZSBOb25lKQoJLHRoZV9kaWN0KQoKZD17J2EnOidmdWNrICcsJ2InOid0aGlzICcsJ2MnOidwbHVzZXMgJ30KcHJpbnQoJ2QgaXNcbicsZCkKcHJpbnQoYWRkZXIoZCkpCg==
stdout
('d is\n', {'a': 'fuck ', 'c': 'pluses ', 'b': 'this '})
stderr
Traceback (most recent call last):
File "prog.py", line 32, in <module>
File "prog.py", line 28, in adder
File "prog.py", line 13, in <lambda>
KeyError: 'fuck pluses '