Answer:
![\textsf{\large{\underline{Solution}:}}](https://img.qammunity.org/2022/formulas/mathematics/high-school/fay55b2kqcqnxeo8m21b800o4lkvc8x6ia.png)
The given problem is solved using language - Python.
def f(x):
new_list=[]
for i in x:
if i%2==0:
new_list.append(i//2)
else:
new_list.append(i*2)
return new_list
my_list=list(range(1,6))
print('Original List:',my_list)
my_list=f(my_list)
print('Modified List:',my_list)
![\textsf{\large{\underline{Logic}:}}](https://img.qammunity.org/2022/formulas/computers-and-technology/high-school/7aaemrr5z6n98xoy9l9i79ipdpjlskef4d.png)
- Create a new list.
- Iterate over the list passed into the function.
- Check if the element is even or not. If true, append half the value of element in the list.
- If false, append twice the value of the element in the list.
- At last, return the new list.
There is another way of doing this - By using map() function.
—————————————————————————————
def f(x):
return list(map(lambda x:x//2 if x%2==0 else 2*x,x))
my_list=list(range(1,6))
print('Original List:',my_list)
my_list=f(2my_list)
print('Modified List:',my_list)
—————————————————————————————
![\textsf{\large{\underline{O{u}tput}:}}](https://img.qammunity.org/2022/formulas/computers-and-technology/high-school/1g9k0ogoz14rzng5b2lag88lvebl5mu70c.png)
Original List: [1, 2, 3, 4, 5]
Modified List: [2, 1, 6, 2, 10]