Re: How to parse this line of code manually



On Aug 28, 11:00 am, Davy <zhushe...@xxxxxxxxx> wrote:
Hi all,

It is well known that Python is appreciated for its merit of concise.
However, I found the over concise code is too hard to understand for
me.

Consider, for instance,
def known_edits2(word):
return set(e2 for e1 in edits1(word) for e2 in edits1(e1) if e2 in
NWORDS)

Shall I understand the code in set() as
for e2 in edits1(e1) {
if e2 in NWORDS {
for e1 in edits1(word) {
e2
}
}

}

[SNIP]
Hi all, I figured it myself. It is left to righ parse, right?
So the above one is like
for e1 in edits1(word) {
for e2 in edits1(e1) {
if e2 in NWORDS {
push e2 to set
}
}
}
And a general question is: Is there any tip available to understand
the code in one line, or what's the parsing priority (left to right,
right to left, or other possibilities)

Any suggestions are welcome!

The code is a simple spell checker fromhttp://www.norvig.com/spell-correct.html

Best regards,
Davy


.



Relevant Pages

  • Re: How to parse this line of code manually
    ... It is well known that Python is appreciated for its merit of concise. ... I found the over concise code is too hard to understand for ... if e2 in NWORDS { ... The idea is known as List comprehension, and comes from ...
    (comp.lang.python)
  • How to parse this line of code manually
    ... It is well known that Python is appreciated for its merit of concise. ... I found the over concise code is too hard to understand for ... Best regards, ...
    (comp.lang.python)
  • Re: How to parse this line of code manually
    ... I found the over concise code is too hard to understand for ... def known_edits2: ... if e2 in NWORDS { ... A 'list comprehension' with parentheses instead of square-brackets ...
    (comp.lang.python)