How should I write this string-prefix check so that it's idiomatic Python?
- by Kevin Stargel
I have a couple of lists of items:
specials = ['apple', 'banana', 'cherry', ...]
smoothies = ['banana-apple', 'mocha mango', ...]
I want to make a new list, special_smoothies, consisting of elements in smoothies that start with the elements in specials. However, if specials is blank, special_smoothies should be identical to smoothies.
What's the most Pythonic way to do this? Is there a way to do this without a separate conditional check on whether specials is blank?