My aim is to create a conditional where: if one of the strings is in the list it gets printed. I tried the following and stuck with this:
Why the output of this code:
strings = ['sdksudfhdsf', 'other', 'sdfsdfwirfkdf', 'another', 'sqdiusaqwe']
substring = 'some_string' or 'other' or 'another' or 'different'
strings_with_substring = [string for string in strings if substring in string]
print(strings_with_substring)
is an empty list
but the above returns the proper values:
strings = ['sdksudfhdsf', 'other', 'sdfsdfwirfkdf', 'another', 'sqdiusaqwe']
substring = 'other' or 'another' or 'different' or 'some_string'
strings_with_substring = [string for string in strings if substring in string]
print(strings_with_substring)
output:
['other', 'another']
Please note that the only thing which I did is to move a 'some_string' to the end of a variable 'substring'