multiply even numbers, add odd numbers
<p>I'm trying to solve how to multiply all even numbers in a list with 2, and add all odd numbers with 7. And then present the list in an descending order. It has to be with a function that takes the list as argument.</p>

<p>I found this here on stackoverflow, but it's not really what I'm after, since the example sums up the even numbers to one product.</p>

<p>This is my code:</p>

<pre><code>L = [45, 22, 2, 498, 78]

def EvenOdd(L):

product = 2
resp = 7
elem = None

for elem, val in enumerate(L):
elem += 1
if elem % 2 == 0:
   product *= elem
if elem % 2 == 1:
   resp += elem
   result = L[elem]
   result.sort()
   result.reverse()
print(result)
</code></pre>

<p>You can create new list using:</p>

<pre><code>new_list = [item * 2 if item % 2 == 0 else item + 7 for item in L]
</code></pre>

<p>and then sort it using:</p>

<pre><code>new_list.sort(reverse=True)
</code></pre>

<p>Output should look like this:</p>

<pre><code>[996, 156, 52, 44, 4]
</code></pre>

python list function