The document describes two Python functions:
1) INDEX_LIST takes a list as input and returns a list of the indices of non-zero elements.
2) lenFOURword takes a list of words as input and returns the indices of words with a length of four letters. Both functions iterate through the input list, check the element based on the specific condition, and append any matching indices to a new list that is returned.
The document describes two Python functions:
1) INDEX_LIST takes a list as input and returns a list of the indices of non-zero elements.
2) lenFOURword takes a list of words as input and returns the indices of words with a length of four letters. Both functions iterate through the input list, check the element based on the specific condition, and append any matching indices to a new list that is returned.
The document describes two Python functions:
1) INDEX_LIST takes a list as input and returns a list of the indices of non-zero elements.
2) lenFOURword takes a list of words as input and returns the indices of words with a length of four letters. Both functions iterate through the input list, check the element based on the specific condition, and append any matching indices to a new list that is returned.
Write a function INDEX_LIST(L), where L is the list of
elements passed as argument to the function. The function returns another list named indexList that stores the indices of all Non-Zero Elements of L. For example: If L contains [12,4,0,11,0,56] The indexList will have - [0,1,3,5] Ans: def INDEX_LIST(L): indexList=[] for i in range(len(L)): if L[i]!=0: indexList.append(i) return indexList L=eval(input("Enter a list")) print(INDEX_LIST(L))
2. Write a function lenFOURword(L), where L is the list of
elements (list of words) passed as argument to the function. The function returns another list named ‘indexList’ that stores the indices of all four lettered word of L. For example: If L contains [“DINESH”, “RAMESH”, “AMAN”,“SURESH”, “KARN”] The indexList will have [2, 4] Ans: def lenFOURword(L): indexList=[] for i in range(len(L)): if len(L[i])==4: indexList.append(i) return indexList L=eval(input("Enter a list")) print(lenFOURword(L))