Extended List Comprehension Syntax : List Comprehension : List PYTHON TUTORIALS


PYTHON TUTORIALS » List » List Comprehension »

 

Extended List Comprehension Syntax


lines = [line.rstrip(  ) for line in open('script1.py') if line[0== 'p']

res = []
for line in open('script1.py'):
    if line[0== 'p':
        res.append(line.rstrip(  ))
print res



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON TUTORIALS

 Navioo List
» List Comprehension