Hi, I'm learning python and I went thru some code that was under the title 'simple python programs' and found this.
I have to say, even using the debugger, I find this code cryptic.
Is it just me? I'd like to know if experienced python coders can read this code and within a short time understand it.
It has what I'd term 'generator' terms, and these terms are embedded \ implicit. i.e.
Will I be expected to work with code like this in a junior level python job? Cos if I am, I think I'd better quit now and go back to C !
Didn't someone say 'explicit is best' ( with reference to declaring 'self' to be a parameter passed to itself in instance methods ) ? Python is the most implicit language I tried to learn, except prolog. But where prolog is all implicit, python seems to be a horribly confusing mix of implicit and explicit. Powerful I'm sure, but extremely hard to read.
its the 8 queens on a chess board problem, but knowing this I still couldn't understand it.
BOARD_SIZE = 8 def under_attack(col, queens): left = right = col for r, c in reversed(queens): left, right = left - 1, right + 1 if c in (left, col, right): return True return False def solve(n): if n == 0: return [[]] smaller_solutions = solve(n - 1) return [solution+[(n,i+1)] for i in xrange(BOARD_SIZE) for solution in smaller_solutions if not under_attack(i+1, solution)] for answer in solve(BOARD_SIZE): print answerIt was my intention to read thru this and a few other programs to see if I could understand them, gain some insight into how python works. If I failed, I could use pyCharm debugger to walk thru each line step by step.
I have to say, even using the debugger, I find this code cryptic.
Is it just me? I'd like to know if experienced python coders can read this code and within a short time understand it.
It has what I'd term 'generator' terms, and these terms are embedded \ implicit. i.e.
Will I be expected to work with code like this in a junior level python job? Cos if I am, I think I'd better quit now and go back to C !
Didn't someone say 'explicit is best' ( with reference to declaring 'self' to be a parameter passed to itself in instance methods ) ? Python is the most implicit language I tried to learn, except prolog. But where prolog is all implicit, python seems to be a horribly confusing mix of implicit and explicit. Powerful I'm sure, but extremely hard to read.
its the 8 queens on a chess board problem, but knowing this I still couldn't understand it.