Is there a function that returns the arrays that are in a list according to the search?
For example I want to get the list of tables containing the letter A
myLst = [[ABC], [BCV], [BAD]]
return [[ABC], [BAD]]
Do I have to make my own function ?
Is there a function that returns the arrays that are in a list according to the search?
For example I want to get the list of tables containing the letter A
myLst = [[ABC], [BCV], [BAD]]
return [[ABC], [BAD]]
Do I have to make my own function ?
Very possible, and simple, just do as follows
if x for x in list if 'a' in x:
#Do something
It's simple list comprehension, I recommend reading Python MDN before starting to code
You can do in one line :
print([item for item in myLst for sub_item in item if 'A' in sub_item])
output:
[['ABC'], ['BAD']]
or as you said you want a function so here is the detailed solution :
def return_list(list_1):
result=[]
for item in list_1:
if isinstance(item,list):
for sub_item in item:
if 'A' in sub_item:
result.append(item)
return result
print(return_list(myLst))