How may I create list of lists in Python to store list of texts? -


i trying open bunch of files directory , trying put results in list of lists say,

that say, have list of file names of directory, want read each 1 of them. after reading each 1 of them, want put results of each file in list. these lists again inserted create list of lists.

to trying write follows:

list_of_files = glob.glob('c:\python27\*.*')     print list_of_files     list1=[]     list2=[]     list_n=[list1,list2]     i,j in zip(list_of_files,list_n):         print i,j         x1=open(i,"r").read()         x2=j.append(x1)     all_sent=list_n     print all_sent 

am doing wrong? if 1 may kindly suggest? there smarter way it? using python2.7 on windows 7 professional edition. have many list of lists question in python have reviewed them. posting did not match. apology cross posting. if may direct me previous post, surely delete post.

try using following list comprehension:

list_of_files = glob.glob('c:\python27\*.*') data = [open(file, 'r').read() file in list_of_files] 

Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -