From ae8a98e30154cc7c5c3e5bad2267d1cde9c9fcc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ozan=20=C3=87a=C4=9Flayan?= Date: Wed, 8 Jun 2011 11:09:27 +0000 Subject: [PATCH] util: Rename concat() to flatten_list() and optimize it --- pisi/util.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pisi/util.py b/pisi/util.py index 382c0374..6e8ce828 100644 --- a/pisi/util.py +++ b/pisi/util.py @@ -64,9 +64,11 @@ class FilePermissionDeniedError(Error): def any(pred, seq): return reduce(operator.or_, map(pred, seq), False) -def concat(l): - """Concatenate a list of lists.""" - return reduce(operator.concat, l) +def flatten_list(l): + """Flatten a list of lists.""" + # Fastest solution is list comprehension + # See: http://stackoverflow.com/questions/952914/making-a-flat-list-out-of-list-of-lists-in-python + return [item for sublist in l for item in sublist] def strlist(l): """Concatenate string reps of l's elements."""