IN ML(NOT PYTHON)
Write a function dupList of type 'a list -> 'a list whose output list is the same as the input list but with each element of the input list repeated twice in a row. For example, if the input is [1, 2, 3], the output list should produce [1, 1, 2, 2, 3, 3]. If the input list [], the output list should be [].
Do not use explicit recursion but use one of the fold functions. Do not write any additional functions, dupList should be the only function.
Code and output
code for copying
def dupList(a):
list1=[]
for i in a:
list1.append(i)
list1.append(i)
return list1
a=list(map(int,input().rstrip().split()))
print(dupList(a))
Code snippet
def dupList(a):
list1=[]
for i in a:
list1.append(i)
list1.append(i)
return list1
a=list(map(int,input().rstrip().split()))
print(dupList(a))
Get Answers For Free
Most questions answered within 1 hours.