Evaluate once or every time

Thomas Passin list1 at tompassin.net
Fri Feb 24 20:36:53 EST 2023


On 2/24/2023 7:00 PM, 2QdxY4RzWzUUiLuE at potatochowder.com wrote:
> On 2023-02-24 at 18:42:39 -0500,
> Thomas Passin <list1 at tompassin.net> wrote:
> 
>> VOWELS = 'aeiouAEIOU'
>> is_vowel = 'y' in VOWELS
>>
>> If I really needed them to be in a list, I'd probably do a list
>> comprehension:
>>
>> VOWEL_LIST = [ch for ch in VOWELS]
> 
> Why use a comprehension when a simple loop will do?  ;-)
> 
> No.  Wait.  That's not what I meant.
> 
> Why use a comprehension when the constructor will do?
> 
> VOWEL_LIST = list(VOWELS)

It just didn't occur to me, I think, that this would create a list of 
the string's characters.  Very nice!



More information about the Python-list mailing list