Respuesta :
Answer:
Explanation:
The following code is written in Python and is a simple function that removes all of the type String elements within the list that has been passed as an argument. Then finally, prints out the list and returns it to the user.
def filter_out_str(list):
for x in list:
if type(x) == type(" "):
list.remove(x)
print(list)
return list

Following are the python code to hold only string value into another list by using the given method:
Python code:
def filter_only_strs(l):#defining the method filter_only_strs that takes list type variable l in parameter
r = []#defining an empty list r
for x in l:#defining a loop that counts value of list
if isinstance(x, str):#using if block that check list value is in string
r.append(x)#using an empty list that holds string value
return r#return list value
l=['d',12,33,"data"]#defining a list l
print(filter_only_strs(l))#calling the method filter_only_strs
Output:
Please find the attached file.
Program Explanation:
- Defining the method "filter_out_strs", which takes one argument of list type that is "l".
- Inside the method, an empty list "r" is defined, and in the next line, a for loop is declared.
- Inside the for loop list "l" is used with a conditional statement that uses the "isinstance" method that checks string value in the list and adds its value in "r", and returns its value.
Find out more about the list in python here:
brainly.com/question/24941798
