A question on the creation of list of lists
subhabrata.banerji at gmail.com
subhabrata.banerji at gmail.com
Wed Apr 22 13:22:51 EDT 2015
On Wednesday, April 22, 2015 at 9:48:44 PM UTC+5:30, subhabrat... at gmail.com wrote:
> Dear Group,
>
> I am trying to open a bunch of files from a directory and trying to put the results in list of lists that is to say,
>
> that is to say,
> I have a list of file names of a directory, I want to read each one of them.
> After reading each one of them, I want to put the results of each file in a list.
> These lists would again be inserted to create a list of lists.
>
> to do this I am trying to write it as follows:
>
> list_of_files = glob.glob('C:\Python27\*.*')
> print list_of_files
> list1=[]
> list2=[]
> list_N=[list1,list2]
> for 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 I doing anything wrong? If any one may kindly suggest?
> Is there any smarter way to do it? I am using Python2.7+
> on MS-Windows 7 Professional Edition.
> Apology for any indentation error.
>
> Regards,
> Subhabrata Banerjee.
I was trying to get some results over small data before putting heavy data, code
seems giving desired output, as in
The name of files are: ['C:\\Python27\\TestDoc\\TestDoc1.txt', 'C:\\Python27\\TestDoc\\TestDoc2.txt', 'C:\\Python27\\TestDoc\\TestDoc3.txt', 'C:\\Python27\\TestDoc\\TestDoc4.txt']
C:\Python27\TestDoc\TestDoc1.txt []
C:\Python27\TestDoc\TestDoc2.txt []
C:\Python27\TestDoc\TestDoc3.txt []
C:\Python27\TestDoc\TestDoc4.txt []
The Contents of file in list of lists: [['There is a home.'], ['One man lives there.'], ['He is tall.'], ['He is good.']]
I am trying to put heavy files with big contents, so was getting confused whether I was going fine. But the way I am creating lists may there be a a better way?
Regards,
Subhabrata Banerjee.
More information about the Python-list
mailing list