[Tutor] 2 problems in a small script
Kent Johnson
kent37 at tds.net
Mon Oct 15 13:36:54 CEST 2007
Dick Moores wrote:
>> If your interested, this could be done succinctly with set types. (no
>> iterating required!)
> Done. I had no idea set could be used that way! With a couple of
> modifications, I used your ideas in both <buggy_For_Web5b.py> and
> <getCrew_ForWeb2.py> (see the thread I started, <
> http://www.nabble.com/An-idea-for-a-script-tf4603558.html#a13149808 >).
You might as well create the set of disallowed letters just once:
astr = set(ascii_letters + digits + '-_')
>
>> OR...
>>
>> my_list = filter(well_formed, my_list)
>
> I'll look into "filter".
The list comp form is actually preferred and IIRC filter() has been
eliminated from Python 3.
>
> A question:
>
> Here's my(yours) well_formed():
>
> def well_formed(word, astr):
> """
> Returns True if set(<a string>) - set(<a string>) is empty; False if
> not.
> """
> return not set(word) - set(astr)
>
> Is it OK to use <a string> like that in a docstring?
Sure why not?
Kent
More information about the Tutor
mailing list