Instructions
Write a function hide_inside that consumes a list, an item, and a nonnegative integer pos.
Your function should produce a new list that contains all theitems of the input list with the new item inserted in positionpos. For example,
hide_inside(["a", "b"], "cat", 1]
will produce ["a", "cat", "b"]. If pos is greater than the length of the list, the item should appear at the end of the list. For example,
hide_inside(["a", "b"], "cat", 20]
will produce ["a", "b", "cat"].
my solution is
def hide_inside(anylist,pos,item):
seq=anylist
if pos>=len(seq):
pos=len(seq)
elif pos<=0:
pos=0
item=item
seq.insert(pos,item)
return seq
Could somebody please help me with this problem
o
Write a function hide_inside that consumes a list, an item, and a nonnegative integer pos.
Your function should produce a new list that contains all theitems of the input list with the new item inserted in positionpos. For example,
hide_inside(["a", "b"], "cat", 1]
will produce ["a", "cat", "b"]. If pos is greater than the length of the list, the item should appear at the end of the list. For example,
hide_inside(["a", "b"], "cat", 20]
will produce ["a", "b", "cat"].
my solution is
def hide_inside(anylist,pos,item):
seq=anylist
if pos>=len(seq):
pos=len(seq)
elif pos<=0:
pos=0
item=item
seq.insert(pos,item)
return seq
Could somebody please help me with this problem
o

