views:

139

answers:

1

I have a regular list comprehension to load all lines of a file in a list

f = open('file')

try:
    self._raw = [L.rstrip('\n') for L in f]
finally:
    f.close()

Now I'd like to insert in the list each line 'n' times on the fly. How to do it inside the list comprehension ?

Tnx

+6  A: 
self._raw = [L.rstrip('\n') for L in f for _ in xrange(n)]
Alex Martelli