I have a list with multiple strings in it: for ex: list=['abc/aed','bcd/eac','rtf/reew','opee/rew']
I want to search if 'aed' is present in list if yes fecth whole string "abc/aed"
how to achieve this using python/pyspark
CodePudding user response:
this should work
my_list=['abc/aed','bcd/eac','rtf/reew','opee/rew']
output = [val for val in my_list if "aed" in val]
CodePudding user response:
We can use a list comprehension:
list = ['abc/aed', 'bcd/eac', 'rtf/reew', 'opee/rew']
output = [x for x in list if "aed" in x]
print(output) # ['abc/aed']
CodePudding user response:
for i in list:
if "aed" in i:
print(i)