List Comprehension Syntax

Eric S. Johansson esj at harvee.org
Sat Jul 10 12:55:24 EDT 2004


Ville Vainio wrote:

> 
> Admittedly I have never used speech recognition software. How do you
> speak out the following equivalent snippets:
> 
> ----
> 
> files = [f.lower() for f in allfiles if f.endswith(".txt")]

files equal sign between brackets foxtrot dot lower matched parens for 
foxtrot in all no space files if foxtrot dot ends no space with matched 
parens between quotes dot tango x-ray tango

is a reasonably close approximation not counting misrecognitions. 
personally, I would never ever use single character variables unless I'm 
typing them and I would never use merged words.  I would always join 
them with _ because it's easier and more accurate than saying no-space. 
  and mixed case is right out because you have to state every time you 
shift case unless NaturallySpeaking just happens to know the word in the 
right case.

and the matched brackets etc. macros are of my own creation

> ----
> 
> 
> files = []

files equal sign matched brackets

> for f in allfiles:

for foxtrot in all no space files :

>   if f.endswith(".txt"):

if foxtrot dot ends no space with between parens between quotes dot 
tango x-ray tango end colon

>     files.append(f.lower())

files dot append between parens foxtrot dot lower matched parens


and it's not fun.  take a look at camram if you want to see a fair 
amount of Python written probably 80 or 90 percent by voice.  Its 
somewhere over 5000 lines of code if I'm not counting improperly.


> If it has something to do with line breaking, the following is
> obviously ok too (and in no way inferior to the one-line approach):

it's easier with speech recognition to say small things and correct 
especially when coding.  unfortunately, NaturallySpeaking does not work 
extremely well with applications that do not use a very limited set of 
edit controls.

---eric




More information about the Python-list mailing list