ezoic

Thursday, October 29, 2015

A tricky program

I have a list of files in python, each of having a bunch of elements. I want to count the total number elements from all of the files. There are two ways to do it:
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. 

Have a good habit on programming

There are some tips on writing program:
1. Try to give the objects some meaningful names, like when I create a list containing a list of fruit. Then we cab type: fruit=['kiwi','orange','pear'], instead b=['kiwi','orange','pear'].
2. Give the files some handles before reading them in, like:
file1="aaa.txt"
file2="bbb.txt"
So when you change the file names to be read in, just change the handles.
3. When a piece of code is repeatedly used, we can code them into functions, or classes etc.

looking for a man

 I am a mid aged woman.  I was born in 1980. I do not have any kid. no complicated  dating before . I am looking for a man here for marriage...