Ask Question
15 February, 19:33

write a function deal3 of type 'a list - > a' list whose output list is the same as the input list, but with the third element deleted.

+2
Answers (1)
  1. 15 February, 19:59
    0
    I am writing a python program for this.

    def deal3 (input_list, index):

    list = []

    for x in range (len (input_list)):

    if x! = index:

    list. append (input_list[x])

    print ('list - >', list)

    input_list = [10, 20, 30, 40, 50]

    index = 2

    deal3 (input_list, index)

    Explanation:

    The first line of code defines a function deal3 which has two parameters. input_list which is an input list and index is the position of elements in the input list. next statement list=[] declares a new list that will be the output list. next statement for x in range (len (input_list)) : is a loop which the loop variable x will traverse through the input list until the end of the input list is reached. the next statement if x! = index: checks if x variable is equal to the position of the element in the list. Next statement list. append (input_list[x]) appends the elements of input list to list (new list that will be the output list). Now the output list will contain all the elements of the input list except for the element in the specified position (index variable). this statement print ('list - >', list) prints the list (new output list). this statement input_list = [10, 20, 30, 40, 50] insert elements 10 20 30 40 50 in the input list. index=2 specifies the second position (3rd element) in the list that is to be removed. deal3 (input_list, index) So the function is called which will remove 3rd element of the input list and prints output array with same elements as that in input array except for the element at the specified position.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “write a function deal3 of type 'a list - > a' list whose output list is the same as the input list, but with the third element deleted. ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers