Write a method doubleUp that doubles the size of a list of integers by doubling-up each element in the list. Assume there's enough space in the array to double the size. Suppose a list stores the values [1, 3, 2, 7]. After calling list.doubleUp(), the list should store the values [1, 1, 3, 3, 2, 2, 7, 7].

Respuesta :

Answer:

def double_up(self, mylist):

   doubled = list()

   for item in mylist:

       for i in range(2):

           doubled.append(item)

   return doubled

Explanation:

The program method double_up gets the list argument, iterates over the list and double of each item is appended to a new list called doubled.

Methods are functions defined in classes. A class is a blueprint of a data structure. Each instance of the same class holds the same attributes and features.