The specific trouble has by now been solved in previous answers, so I'll deal with the general idea of applying conditionals inside list comprehensions.The results demonstrate that Should the iterable includes only a few interior iterables then sum will likely be quickest, nevertheless for very long iterables only the itertools.A Certificate in Fam