Python for loop control variable accessed before declaration -


this question has answer here:

i'm new python, , i'm trying understand following line:

    "".join(char char in input if not unicodedata.category(char).startswith('p')) 

source: https://stackoverflow.com/a/11066443/3818487

this code removes unicode punctuation input. don't understand why works. far can tell, iterates on characters in input ignoring punctuation characters. how can access char before declared in loop? come java background, confusing me.

this comprehension more following, in regular code (using list store our non-punctuation characters).

#input defined somewhere prior loop output = [] char in input:     if not unicodedata.category(char).startswith('p'):         output.append(char) ''.join(output) 

comprehensions iterate on loop portion first, value being iterated on over left.


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -