I have a data set as a list. From that list I need to find a keyword, and if found, I should be able to extract the complete information of that element.
att =['Email/[email protected]', 'CountryCode/US','CountryCode/UK', 'ID/12345']
from the above list, if I search only CountryCode, then the output should come as:
['CountryCode/US','CountryCode/UK']
Below is my code which I am trying, but it is returning only a single value.
Can some one help me with this code, to return all of the values as :
['CountryCode/US','CountryCode/UK']
def att_func(field,data):
for i, j in enumerate(data):
# print(i,j)
if field in j:
return [data[i]]
att =['Email/[email protected]', 'CountryCode/US','CountryCode/UK', 'ID/12345']
field ='CountryCode'
Cntry = att_func('CountryCode',att)
print(Cntry)