Answer:
The function in Python is as follows:
def myfunction(mylist):
listitems = ""
for i in range(len(mylist)):
if (i < len(mylist)-1):
listitems = listitems + mylist[i] + ", "
else:
listitems = listitems + "and "+mylist[i]
return listitems
Explanation:
This defines the function
def myfunction(mylist):
This initializes an empty string which in the long run, will be used to hold all strings in the list
listitems = ""
This iterates through the list
for i in range(len(mylist)):
For list items other than the last item, this separates them with comma (,)
if (i < len(mylist)-1):
listitems = listitems + mylist[i] + ", "
For the last item, this separates with and
else:
listitems = listitems + "and "+mylist[i]
This returns the required string
return listitems