Is there any equivalent 'LIKE' function(like in MySQL) for lists. for example;
This is my list:
abc = ['one', 'two', 'three', 'twenty one']
if I give the word "on", it should print the matching words from the list (in this case: 'one', 'twenty one') and if I give "fo", it should print False
You can use list comprehension:
[m for m in abc if 'on' in m]
This roughly translates to "for each element in abc, append element to a list if the element contains the substring 'on'"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With