IN SML
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.
duplist is enough to get that output and You can achieve this in many ways I have used List Concatenation property and Sorted it to make output look alike your requirement.
Here is my function :
def dupList(initial): final = [] final = sorted(initial+initial) return final input_list = [1,2,3,4,5] print(dupList(input_list))
Further if any query comment it
I will help you .
Have a nice day.
Get Answers For Free
Most questions answered within 1 hours.