1. concatenate all the sub files into one list, and count all the elements in the bigger list. But when I try to concatenate all the sub files into one list, it exceeded the memory quota.
2. read in one file into one list each time, and count the number of elements in the list, and add the number of the elements of each list together, each time initialize one new list when reading in a new file.
import glob
a=0
for file in glob.glob("/home/adam/*.txt"):list=[]
file=open(file,'rb') as b:
for row in b:
list.append(b)
a=a+len(list)
print a
then , we will see the total number of elements from printing a.
No comments:
Post a Comment