How is this evaluated

newspost2012 at gmx.de newspost2012 at gmx.de
Thu Jul 4 14:07:57 EDT 2013


Am Donnerstag, 4. Juli 2013 19:20:43 UTC+2 schrieb Arturo B:
> ...
> So I want to question:
> How is the 
> 
> if 'h' in consonants else 'h' for 'h' in s
> 
> part evaluated? (step by step please :P )

Although new to python I think I can solve this (if no one contradicts, I can guess that I understood it :-) ):

Take every letter from the string, one after the other, (for l in s).
If you can find the letter in the string constants (if l in constants) then take it, append an "o" and then the letter again and return it (l + 'o' + l) if not, return the letter as it is (else l).

Or in applicable order:
take 'h' append 'o' append 'h' and return this, if you can find 'h' in constants, if not return just 'h' (and do this for every letter in string s)

hth,
Martin



More information about the Python-list mailing list