From 7ee2c4ad8fef637d4840e35b1758f4133a6571ba Mon Sep 17 00:00:00 2001 From: neingeist Date: Sat, 30 May 2015 21:10:28 +0200 Subject: [PATCH] n-queens: use list comprehension instead of for loop --- n-queens.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/n-queens.py b/n-queens.py index f0ad428..80a9473 100755 --- a/n-queens.py +++ b/n-queens.py @@ -32,11 +32,8 @@ def solve(n): positions[row]-k != positions[row+k] for row in range(0, n-1) for k in range(1, n-row))) - solutions = [] - for positions in permutations(range(1, n+1)): - if valid(positions): - solutions.append(positions) - return solutions + return [positions for positions in permutations(range(1, n+1)) + if valid(positions)] def fundamental(solutions):