pattern matching, tuples and multiplication in Python
What is be best way to reduce this series of tuples ('x', 0.29, 'a') ('x', 0.04, 'a') ('x', 0.03, 'b') ('x', 0.02, 'b') ('x', 0.01, 'b') ('x', 0.20, 'c') ('x', 0.20, 'c') ('x', 0.10, 'c') into: ('x', 0.29 * 0.04 , 'a') ('x', 0.03 * 0.02 * 0.01, 'b') ('x', 0.20 * 0.20 * 0.10, 'c') EDIT: X is a constant, it is known in advance and can be safely ignored And the data can be treated as pre-sorted on the third element as it appears above. I am trying to do it at the moment using operator.mul, and a lot of pattern matching, and the odd lambda function... but I'm sure there must be an easier way! Can