I have to write a function dup_elt(lst, pos=0) that takes a list and expands it by duplicating the element in position pos, returning a new list.
Examples:
dup_elt([1, 2, 100, 8]) # [1, 1, 2, 100, 8]
dup_elt([1, 2, 100, 8], 2) # [1, 2, 100, 100, 8]
dup_elt([1, 2, 100, 8], 10) # [1, 2, 100, 8]
Assuming that lst is a non-empty list and pos is a non-negative int. If lst[pos] does not exist, lst should be returned unchanged.
Optional argument: The argument specification pos=0 assigns the default value of 0 to pos if omitted from the function call.
I have done:
def dup_elt(lst,pos=0):
return ([lst],(pos,pos))
However, that doesn't duplicate the list item.