Question

In: Computer Science

USING PYTHON, write a function that takes a list of integers as input and returns a...

USING PYTHON, write a function that takes a list of integers as input and returns a list with only the even numbers in descending order (Largest to smallest)

Example: Input list: [1,6,3,8,2,5] List returned: [8, 6, 2].

DO NOT use any special or built in functions like append, reverse etc.

Solutions

Expert Solution

source code:


def bubbleSort(arr):
n = len(arr)
  
# Traverse through all array elements
for i in range(n-1):
# range(n) also work but outer loop will repeat one time more than needed.
  
# Last i elements are already in place
for j in range(0, n-i-1):
  
# traverse the array from 0 to n-i-1
# Swap if the element found is greater
# than the next element
if arr[j] < arr[j+1] :
arr[j], arr[j+1] = arr[j+1], arr[j]
  
def even(l):
for i in l:
if(int(i)%2==1):
l.remove(i)
bubbleSort(l)
return l


print(even( [1,6,3,8,2,5] ))
  


Related Solutions

Write a function that takes a list of integers as input and returns a list with...
Write a function that takes a list of integers as input and returns a list with only the even numbers in descending order (Largest to smallest) Example: Input list: [1,6,3,8,2,5] List returned: [8, 6, 2] Do not use any special or built in functions like append, reverse etc.
Write a Python function that takes a list of integers as a parameter and returns the...
Write a Python function that takes a list of integers as a parameter and returns the sum of the elements in the list. Thank you.
Write a Python function that takes a list of integers as a parameter and returns the...
Write a Python function that takes a list of integers as a parameter and returns the sum of the elements in the list. Thank you.
Write a Scheme function that takes a list of integers and returns all odd integers on...
Write a Scheme function that takes a list of integers and returns all odd integers on the list in the original order: (odd-numbers `(2 4 9 16 25 7)) (9 25 7) Hint: 2 (remainder 13 5) 3 Please explain every step
1.Write a function div7(lst) which takes in a list of integers, and returns a list of...
1.Write a function div7(lst) which takes in a list of integers, and returns a list of booleans of the same length, such that for each integer in the original list, the boolean in the output list is True if that integer was divisible by 7, or False if not. Use list comprehensions in python, the function only could be at most two lines long. Here is some examples: >>> div7([14, 5, 7, 3, 29, 28, 10]) [True, False, True, False,...
C++ write a function called divideBy that takes two integers as its input and returns the...
C++ write a function called divideBy that takes two integers as its input and returns the remainder. If the divisor is 0, the function should return -1, else it should return the remainder to the calling function.
Write a PYTHON function CommonLetters(mystring) that takes mystring as input and returns the number of letters...
Write a PYTHON function CommonLetters(mystring) that takes mystring as input and returns the number of letters in mystring that also occur in the string ‘Python’. Using above function, write a program that repeatedly prompts the user for a string and then prints the number of letters in the string that are also in string ‘Python’. The program terminates when the user types an empty string.
Write a Scheme function that takes two integers and returns the list of all integer numbers...
Write a Scheme function that takes two integers and returns the list of all integer numbers between these two integers (inclusively) in increasing order. (numbers 10 20) (10 11 12 13 14 15 16 17 18 19 20) Please explain every step.
PYTHON 3: Write a recursive function that takes a non-negative integer n as input and returns...
PYTHON 3: Write a recursive function that takes a non-negative integer n as input and returns the number of 1's in the binary representation of n. Use the fact that this is equal to the number of 1's in the representation of n//2 (integer division) plus 1 if n is odd. >>>numOnes(0) 0 >>>numOnes(1) 1 >>>numOnes(14) 3
All functions are written in python Write a function cube_evens_lc(values) that takes as input a list...
All functions are written in python Write a function cube_evens_lc(values) that takes as input a list of numbers called values, and that uses a list comprehension to create and return a list containing the cubes of the even numbers in values (i.e., the even numbers raised to the third power). For example: >>> cube_evens_lc([2, 5, 6, 4, 1]) result: [8, 216, 64] This version of the function may not use recursion. Write a function cube_evens_rec(values) that takes as input a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT