# Sort an array by value and index

Your task is to sort an array of integer numbers by the product of the value and the index of the positions.

For sorting the index starts at 1, NOT at 0!
The sorting has to be ascending.
The array will never be null and will always contain numbers.

Example:
```
Input: 23, 2, 3, 4, 5
Product of value and index:
23 => 23 * 1 = 23  -> Output-Pos 4
 2 =>  2 * 2 = 4   -> Output-Pos 1
 3 =>  3 * 3 = 9   -> Output-Pos 2
 4 =>  4 * 4 = 16  -> Output-Pos 3
 5 =>  5 * 5 = 25  -> Output-Pos 5

Output: 2, 3, 4, 23, 5
```

Have fun coding it and please don't forget to vote and rank this kata! :-) 

I have also created other katas. Take a look if you enjoyed this kata!

Difficulty: introductory

Starter code:

def sort_by_value_and_index(arr):
	

Solutions:
def sort_by_value_and_index(arr):
    return [y[1] for y in sorted(enumerate(arr),key=lambda x:(x[0] + 1) * x[1])]

def sort_by_value_and_index(arr):
    return [b for _, b in sorted(enumerate(arr, 1), key=lambda x: int.__mul__(*x))]

def sort_by_value_and_index(arr):
    return [b for _, b in sorted(enumerate(arr, 1), key=lambda a: a[0] * a[1])]


def sort_by_value_and_index(arr):
    return [e for i, e in sorted(enumerate(arr, 1), key=lambda t: t[0] * t[1])]

def sort_by_value_and_index(arr):
    return [elem[1] for elem in sorted(enumerate(arr, 1), key=lambda elem: elem[0]*elem[1])]

import itertools
def sort_by_value_and_index(nums):
    #your code here
    seq = itertools.count(1)
    return sorted(nums, key=lambda num:num*next(seq))

def sort_by_value_and_index(arr):
    arr = zip(range(1, len(arr) + 1), arr)
    return [x[1] for x in sorted(arr, key=lambda x: x[0] * x[1])]

def sort_by_value_and_index(arr):
    vals = [(index + 1) * element for index, element in enumerate(arr)]
    newList = [(i, j) for i, j in zip(vals, arr)]
    newList = sorted(newList, key = lambda element: (element[0]))
    return [i[1] for i in newList]

def sort_by_value_and_index(arr):
    return [y for x, y in sorted(enumerate(arr, 1), key=lambda x: x[0] * x[1])]

sort_by_value_and_index = lambda arr: [elem for key, original_index, elem in sorted(((i * elem, i, elem) for i, elem in enumerate(arr, 1)))]