Python for loop control variable accessed before declaration -
this question has answer here:
- python for-in loop preceded variable 4 answers
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
Post a Comment