Question

I need to remove the even numbers in the back of the list, any ideas? #f....

I need to remove the even numbers in the back of the list, any ideas?

#f. Demonstrate moving even elements to the front of the list.
data = list(ONE_TEN)
def evenToFront(data):
for i in range(len(data)):
if i % 2 == 0:
data.insert(0, i)

comments too please

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def evenToFront(data):
    for i in range(len(data)):
        x = data[i]
        if x % 2 == 0:
            data.remove(x)
            data.insert(0, x)

# Testing
data = [1,2,3,4,5,6,7,8,9,10]
evenToFront(data)
print(data)

Add a comment
Know the answer?
Add Answer to:
I need to remove the even numbers in the back of the list, any ideas? #f....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • def countEvens(listOfInts): ''' - Returns an integer value representing the number of even numbers that exist...

    def countEvens(listOfInts): ''' - Returns an integer value representing the number of even numbers that exist in listOfInts. - Return 0 if listOfInts is not a list type or if no even number exists in listOfInts. - Note: elements in listOfInts can contain any data type. ''' return "stub" # Tests for countEvens def test_countEvens_1(): assert countEvens([0,2,4]) == 3 def test_countEvens_2(): assert countEvens([0,"2","Four", 6]) == 2 def test_countEvens_3(): assert countEvens((0,2,4)) == 0 def test_countEvens_4(): assert countEvens([-1,1,3,5,7]) == 0 def test_countEvens_5():...

  • def slice_list(lst: List[Any], n: int) -> List[List[Any]]: """ Return a list containing slices of <lst> in...

    def slice_list(lst: List[Any], n: int) -> List[List[Any]]: """ Return a list containing slices of <lst> in order. Each slice is a list of size <n> containing the next <n> elements in <lst>. The last slice may contain fewer than <n> elements in order to make sure that the returned list contains all elements in <lst>. === Precondition === n <= len(lst) >>> slice_list([3, 4, 6, 2, 3], 2) == [[3, 4], [6, 2], [3]] True >>> slice_list(['a', 1, 6.0, False],...

  • Write an implementation similar to the Priority Queue method (from chapter 26) to the linked list...

    Write an implementation similar to the Priority Queue method (from chapter 26) to the linked list using node. (from chapter 24). Your code should utilize the selectionsort method from attached and create another method call selectionsort in linkedlist class. To demonstrate the usage of the selection sort method, you should manually create a link list of random integer (say of 5 numbers), and you need to demonstrate the use the selection sort to sorted the link list. Please submit your...

  • HI I would like to ask how to write the function when my list is [[1,2,4],[0,3,2]]....

    HI I would like to ask how to write the function when my list is [[1,2,4],[0,3,2]]. Like merging them. I managed to do it separately only. The mean for [1,2,4] is 2.33 and so xbar return me [-1.33,-0.33,1.67] (is like [1,2,4] minus the 2.33. I need help for more lists. Thanks >>> def mean(Ist): return sum(Ist)/len(Ist) >>> def xbar(data): i = 0 a = mean(data) for i in range(len(data)): data[i] -= a i += 1 return data >>> xbar([1,2,4]) [-1.3333333333333335,...

  • need help on all parts please and thank you (e) What is the correct output of...

    need help on all parts please and thank you (e) What is the correct output of this code? (2 pts) >>> def func(x): >>> res = 0 >>> for i in range (len (x)): res i >>> return res >>> print (func(4)) ( 4 5 ) 6 ()7 ( What could be described as an immutable list? (2 pts) () a dimple ( ) a tuple ( ) a truffle () a dictionary (g) What is the result of the...

  • I am using python3.6 and i am getting an error on line 42 num = int(fin.readline())...

    I am using python3.6 and i am getting an error on line 42 num = int(fin.readline()) #reading first value valueError: invalid literal, for int() with base 10 Any help is appreciated, here is the code. reads from txt file a few integers in an array and sorts them. thank you! # Function to do insertion sort def insertionSort(arr):     # Traverse through 1 to len(arr)     for i in range(1, len(arr)):         key = arr[i]         # Move elements of...

  • Hey guys I need help with this question with 3 sub-problems. f test remove short synonyms () Define the remove shorti s...

    Hey guys I need help with this question with 3 sub-problems. f test remove short synonyms () Define the remove shorti synonyms function which is passed a dictionary as a parameter- The keys of the parameter dictionary are words and the corresponding values are 1ists of synonyms (synonyms are words which have the same or nearly the same meaning). The function romoves all the eynonyme which have ous than 8 charactors from each corresponding list of synonyms-As well, the funet...

  • ONE_TEN = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] Demonstrate replacing values with...

    ONE_TEN = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] Demonstrate replacing values with the larger of their neighbors and demonstrate shifting to the right replacing the furthermost element with the first element in the list. data = list(ONE_TEN) def replaceNeighbors(data): for i in range(len(data)): if data[i] < data[i+1]: data[i] == data[i+1] replaceNeighbors(data) print("After replacing with neighbors: ", data) data = list(ONE_TEN) def shiftRight(data): data= data[-1] + dta[:-1] shiftRight(data) print("After shifting right: ", data) im having trouble with...

  • Please, I need help debuuging my code. Sample output is below MINN = 1 MAXX =...

    Please, I need help debuuging my code. Sample output is below MINN = 1 MAXX = 100 #gets an integer def getValidInt(MINN, MAXX):     message = "Enter an integer between" + str(MINN) + "and" + str(MAXX)+ "(inclusive): "#message to ask the user     num = int(input(message))     while num < MINN or num > MAXX:         print("Invalid choice!")         num = int(input(message))     #return result     return num #counts dupes def twoInARow(numbers):     ans = "No duplicates next to each...

  • Need help the first picture is the code I have so far the second are the...

    Need help the first picture is the code I have so far the second are the requirements. It’s a deque array in python class dequeArray: DEFAULT-CAPACITY 10 #moderate capacity for all new queues def init (self): self.capacity-5 capacity self.capacity self.data self, make array(self. capacity) self. size self. front-θ def len (self): return self. size def _getiten-(self, k); #Return element at index k if not θ k < self. size: raise IndexError('invalid index) return self._data[k] def isEmpty(self): if self. data0: return...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT