4
$\begingroup$

I have the list:

List1={{7, -0.9}, {10,-1}, {12, -2}, {15, -2}}

Would like to receive the next list:

List2={{7, -0.9*2*List1[[1]][[1]]}, {10,-1*2*List1[[2]][[1]]}, {12, -2*2*List1[[3]][[1]]}, {15, -2*2*List1[[4]][[1]]}}

Those multiply all second elements of the list by 2, and then by the corresponding first element How can this be done?

$\endgroup$

3 Answers 3

10
$\begingroup$
List1 /. {f_, l_} :> {f, 2*l*f}
$\endgroup$
5
$\begingroup$
MapApply[{#1, 2 #1 #2}&]@List1

(* {{7, -12.6}, {10, -20}, {12, -48}, {15, -60}} *)

Or

{#[[All,1]], 2 #[[All,1]] #[[All,2]]}&@List1//Transpose
$\endgroup$
2
$\begingroup$
list = {{7, -0.9}, {10, -1}, {12, -2}, {15, -2}};

A variant of 1066's answer

{#, 2 ##} & @@@ list

{{7, -12.6}, {10, -20}, {12, -48}, {15, -60}}

Using Cases

Cases[list, {a_, b_} :> {a, 2 a b}]

{{7, -12.6}, {10, -20}, {12, -48}, {15, -60}}

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.