Answer:
The solution in Python is as follows:
class myClass:
def doubleUp(self,doubleList):
doubleList[:0] = doubleList[::2] = doubleList[1::2] = doubleList[:]
newlist = []
n = int(input("Number of elements: "))
for i in range(n):
num = int(input(": "))
newlist.append(num)
list = myClass()
list.doubleUp(newlist)
print(newlist)
Explanation:
Start by creating a class
The solution in Python is as follows:
class myClass:
Then define the method doubleUp
def doubleUp(self,doubleList):
The duplicates is done here
doubleList[:0] = doubleList[::2] = doubleList[1::2] = doubleList[:]
The program main begins here
This defines an empty list
newlist = []
This prompts user for number of elements
n = int(input("Number of elements: "))
The following iteration get the elements of the list
<em>for i in range(n):</em>
<em> num = int(input(": "))</em>
<em> newlist.append(num)</em>
This defines the instance of the class
list = myClass()
This calls the method
list.doubleUp(newlist)
Lastly, this prints the duplicate list
print(newlist)